diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-11 17:47:25 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-11 17:47:25 +0200 |
commit | e612a7e78883c91b008d97585f1e4f73d773d490 (patch) | |
tree | c4a52797511a403aa1f40be6cd88309473f90839 | |
parent | 519ad40a1703ef064a068ab0cd759d62c72d09e1 (diff) | |
download | gdx-boardgame-e612a7e78883c91b008d97585f1e4f73d773d490.zip gdx-boardgame-e612a7e78883c91b008d97585f1e4f73d773d490.tar.gz |
BounceAnimation : support optional rotation movement
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java | 30 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java | 2 |
2 files changed, 27 insertions, 5 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java index 22aa470..271728c 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java @@ -18,29 +18,43 @@ public class BounceAnimation extends TimedAnimation } }; - public static BounceAnimation get(Piece piece, float duration, float bounceFactor) + public static BounceAnimation get(Piece piece, float duration, float bounceFactor, int rotations) { BounceAnimation a = bounceAnimationPool.obtain(); a.piece = piece; a.bounceFactor = bounceFactor; a.setDuration(duration); + a.computeRotationDegrees(rotations); return a; } private Piece piece; + private float startScale; + private float startRotation; private float bounceFactor; + private float rotationDegrees; private BounceAnimation() { } - public BounceAnimation(Piece piece, float duration, float bounceFactor) + public BounceAnimation(Piece piece, float duration, float bounceFactor, int rotations) { this.piece = piece; this.bounceFactor = bounceFactor; this.setDuration(duration); + this.computeRotationDegrees(rotations); + } + + private void computeRotationDegrees(int rotations) + { + if (rotations == 0) { + rotationDegrees = 0f; + } else { + rotationDegrees = (360 * rotations); + } } @Override public void dispose() @@ -50,16 +64,24 @@ public class BounceAnimation extends TimedAnimation @Override protected void begin() { + this.startScale = piece.getScale(); + this.startRotation = piece.getRotation(); } @Override protected void end() { - piece.setScale(1f); + piece.setScale(this.startScale); + if (rotationDegrees != 0f) { + piece.setRotation(this.startRotation); + } } @Override protected void update(float percent) { - piece.setScale(1 + bounceFactor * (float) Math.sin(percent * Math.PI)); + piece.setScale(this.startScale + this.bounceFactor * (float) Math.sin(percent * Math.PI)); + if (rotationDegrees != 0f) { + piece.setRotation(this.startRotation + (percent * this.rotationDegrees)); + } } @Override public void draw(Batch batch) diff --git a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java index b21da4d..010506e 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java @@ -61,7 +61,7 @@ public class AnimationsScreen extends AbstractScreen { switch (state) { case BOUNCE: - animation = BounceAnimation.get(panzer, 2f, 3f); + animation = BounceAnimation.get(panzer, 2f, 3f, -1); case DONE: app.switchToMenu(); } |