From 3d5471cc3a2cf6cd5341475b3549c804449d623d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 7 Dec 2018 00:53:39 +0100 Subject: MoveAnimation : add Sound support --- .../gdx/boardgame/animations/MoveAnimation.java | 24 +++++++++++++++++----- 1 file 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; } } -- cgit v1.1-2-g2b99