examples/drag: Put the moving sprites frontend

This commit is contained in:
Hajime Hoshi 2018-05-12 23:22:50 +09:00
parent 62c5511314
commit f7c19ef517

View File

@ -287,18 +287,20 @@ func (g *Game) update(screen *ebiten.Image) error {
return nil
}
ss := map[*Sprite]*Stroke{}
movingSprites := map[*Sprite]struct{}{}
for s := range g.strokes {
ss[s.DraggingObject().(*Sprite)] = s
movingSprites[s.DraggingObject().(*Sprite)] = struct{}{}
}
for _, s := range g.sprites {
if stroke, ok := ss[s]; ok {
dx, dy := stroke.PositionDiff()
s.Draw(screen, dx, dy, 0.5)
} else {
if _, ok := movingSprites[s]; ok {
continue
}
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!")