mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
examples/2048: Make it smoother
This commit is contained in:
parent
ced66ff319
commit
2c4b9c1dbe
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user