diff --git a/examples/drag/main.go b/examples/drag/main.go index 89166a4bc..20f3640ca 100644 --- a/examples/drag/main.go +++ b/examples/drag/main.go @@ -287,20 +287,24 @@ func (g *Game) update(screen *ebiten.Image) error { return nil } - movingSprites := map[*Sprite]struct{}{} + draggingSprites := map[*Sprite]struct{}{} for s := range g.strokes { - movingSprites[s.DraggingObject().(*Sprite)] = struct{}{} + if sprite := s.DraggingObject().(*Sprite); sprite != nil { + draggingSprites[sprite] = struct{}{} + } } for _, s := range g.sprites { - if _, ok := movingSprites[s]; ok { + if _, ok := draggingSprites[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) + if sprite := s.DraggingObject().(*Sprite); sprite != nil { + sprite.Draw(screen, dx, dy, 0.5) + } } ebitenutil.DebugPrint(screen, "Drag & Drop the sprites!")