From 2c4b9c1dbe80d43336d296933ddc8af9b9df510c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 1 Aug 2016 02:42:06 +0900 Subject: [PATCH] examples/2048: Make it smoother --- examples/2048/2048/board.go | 11 +++-------- examples/2048/2048/tile.go | 6 ++++-- 2 files changed, 7 insertions(+), 10 deletions(-) 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 {