diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-12-07 00:53:39 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-12-07 00:53:39 +0100 |
commit | 3d5471cc3a2cf6cd5341475b3549c804449d623d (patch) | |
tree | b0dc2f1aa3544c6a887ad9ca936e8d0077b0d8ed /core | |
parent | 7f207d82e58be80dc2ddce6b2863ef01c7cac65a (diff) | |
download | gdx-boardgame-3d5471cc3a2cf6cd5341475b3549c804449d623d.zip gdx-boardgame-3d5471cc3a2cf6cd5341475b3549c804449d623d.tar.gz |
MoveAnimation : add Sound support
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java index b5480d7..c0b4987 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java @@ -1,5 +1,6 @@ package ch.asynk.gdx.boardgame.animations; +import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.math.Vector3; @@ -22,13 +23,14 @@ public class MoveAnimation implements Animation, Pool.Poolable } }; - public static MoveAnimation obtain(Piece piece, Path path, float speed, MoveAnimationCb cb) + public static MoveAnimation obtain(Piece piece, Path path, float speed, Sound snd, MoveAnimationCb cb) { MoveAnimation a = moveAnimationPool.obtain(); a.piece = piece; a.path = path; a.speed = speed; + a.snd = snd; a.cb = cb; a.init(); @@ -45,6 +47,7 @@ public class MoveAnimation implements Animation, Pool.Poolable private boolean notify; private Vector3 dst = new Vector3(); private Vector3 dt = new Vector3(); + private Sound snd; private MoveAnimation() { @@ -97,9 +100,14 @@ public class MoveAnimation implements Animation, Pool.Poolable @Override public boolean animate(float delta) { - if (notify && percent == 0f) { - cb.onTileChange(piece, path); - notify = false; + if (percent == 0f) { + if (snd != null) { + snd.loop(); + } + if (notify) { + cb.onTileChange(piece, path); + notify = false; + } } piece.translate(dt.x * delta, dt.y * delta); piece.rotate(dt.z * delta); @@ -119,6 +127,12 @@ public class MoveAnimation implements Animation, Pool.Poolable } } - return (percent >= 1f); + if (percent >= 1f) { + if (snd != null) { + snd.stop(); + } + return true; + } + return false; } } |