mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
examples/drag: Put the moving sprites frontend
This commit is contained in:
parent
62c5511314
commit
f7c19ef517
@ -287,18 +287,20 @@ func (g *Game) update(screen *ebiten.Image) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ss := map[*Sprite]*Stroke{}
|
movingSprites := map[*Sprite]struct{}{}
|
||||||
for s := range g.strokes {
|
for s := range g.strokes {
|
||||||
ss[s.DraggingObject().(*Sprite)] = s
|
movingSprites[s.DraggingObject().(*Sprite)] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range g.sprites {
|
for _, s := range g.sprites {
|
||||||
if stroke, ok := ss[s]; ok {
|
if _, ok := movingSprites[s]; ok {
|
||||||
dx, dy := stroke.PositionDiff()
|
continue
|
||||||
s.Draw(screen, dx, dy, 0.5)
|
}
|
||||||
} else {
|
|
||||||
s.Draw(screen, 0, 0, 1)
|
s.Draw(screen, 0, 0, 1)
|
||||||
}
|
}
|
||||||
|
for s := range g.strokes {
|
||||||
|
dx, dy := s.PositionDiff()
|
||||||
|
s.DraggingObject().(*Sprite).Draw(screen, dx, dy, 0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
ebitenutil.DebugPrint(screen, "Drag & Drop the sprites!")
|
ebitenutil.DebugPrint(screen, "Drag & Drop the sprites!")
|
||||||
|
Loading…
Reference in New Issue
Block a user