From e612a7e78883c91b008d97585f1e4f73d773d490 Mon Sep 17 00:00:00 2001 From: Jérémy Zurcher Date: Thu, 11 Oct 2018 17:47:25 +0200 Subject: BounceAnimation : support optional rotation movement --- .../gdx/boardgame/animations/BounceAnimation.java | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'core') 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) -- cgit v1.2.3