From 2420e7a8cb388a36094ce846760fa3a18bab2699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 18 Oct 2018 17:12:11 +0200 Subject: MoveAnimation : notify on start and end of animation --- .../ch/asynk/gdx/boardgame/animations/MoveAnimation.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java index 823f7c6..4771590 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java @@ -59,6 +59,7 @@ public class MoveAnimation implements Animation, Pool.Poolable setNextMove(); percent = 0f; dp = 1f * speed; + notify = true; } private boolean setNextMove() @@ -77,7 +78,7 @@ public class MoveAnimation implements Animation, Pool.Poolable (dst.y - piece.getY()) * speed, (dr) * speed ); - notify = (dr == 0 ? true : false); + notify = (dr == 0 ? (cb != null) : false); return done; } @@ -100,18 +101,25 @@ public class MoveAnimation implements Animation, Pool.Poolable @Override public boolean animate(float delta) { + if (notify && percent == 0f) { + cb.onTileChange(piece, path); + notify = false; + } piece.translate(dt.x * delta, dt.y * delta); piece.rotate(dt.z * delta); percent += (dp * delta); - if (notify && cb != null && percent >= 0.5f) { + if (notify && percent >= 0.5f) { cb.onTileChange(piece, path); notify = false; } if (percent >= 1f) { piece.setPosition(dst.x, dst.y, dst.z); if (!setNextMove()) { - percent = 0f; + percent = 0.0001f; + } else if (notify) { + cb.onTileChange(piece, path); + notify = false; } } -- cgit v1.1-2-g2b99