summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java30
1 files changed, 26 insertions, 4 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)