diff --git a/examples/2048/2048/board.go b/examples/2048/2048/board.go index 290965bbf..1b1bc6469 100644 --- a/examples/2048/2048/board.go +++ b/examples/2048/2048/board.go @@ -69,6 +69,9 @@ func (b *Board) Update(input *Input) error { } func (b *Board) Move(dir Dir) error { + for t := range b.tiles { + t.stopAnimation() + } if !MoveTiles(b.tiles, b.size, dir) { return nil } @@ -100,14 +103,6 @@ func (b *Board) Move(dir Dir) error { } return taskTerminated }) - b.tasks = append(b.tasks, func() error { - for t := range b.tiles { - if t.isAnimating() { - return nil - } - } - return taskTerminated - }) return nil } diff --git a/examples/2048/2048/tile.go b/examples/2048/2048/tile.go index fcab366c0..4eabf33e3 100644 --- a/examples/2048/2048/tile.go +++ b/examples/2048/2048/tile.go @@ -70,8 +70,10 @@ func (t *Tile) IsMoving() bool { return 0 < t.movingCount } -func (t *Tile) isAnimating() bool { - return 0 < t.movingCount || 0 < t.startPoppingCount || 0 < t.poppingCount +func (t *Tile) stopAnimation() { + t.movingCount = 0 + t.startPoppingCount = 0 + t.poppingCount = 0 } func tileAt(tiles map[*Tile]struct{}, x, y int) *Tile {