summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-03-31 14:32:30 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-03-31 14:32:30 +0200
commit6859800c15183cc1669285635778269c52df662b (patch)
treeb0a52147bd6e17ed2245dabef439d69c002d54ef /core
parent742754ebb1ca82bde1e3ea6ef7abad10b24e7597 (diff)
downloadRustAndDust-6859800c15183cc1669285635778269c52df662b.zip
RustAndDust-6859800c15183cc1669285635778269c52df662b.tar.gz
add engine/gfx/animations/BounceAnimation
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java b/core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java
new file mode 100644
index 0000000..d4f57a8
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java
@@ -0,0 +1,66 @@
+package ch.asynk.rustanddust.engine.gfx.animations;
+
+import java.lang.Math;
+
+import com.badlogic.gdx.utils.Pool;
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+
+import ch.asynk.rustanddust.engine.gfx.Moveable;
+
+public class BounceAnimation extends TimedAnimation
+{
+ public static float bounceFactor = 0.3f;
+
+ private Moveable moveable;
+
+ private static final Pool<BounceAnimation> bounceAnimationPool = new Pool<BounceAnimation>() {
+ @Override
+ protected BounceAnimation newObject() {
+ return new BounceAnimation();
+ }
+ };
+
+ public static BounceAnimation get(Moveable moveable, float duration)
+ {
+ BounceAnimation a = bounceAnimationPool.obtain();
+
+ a.moveable = moveable;
+ a.duration = duration;
+
+ return a;
+ }
+
+ @Override
+ public void dispose()
+ {
+ bounceAnimationPool.free(this);
+ }
+
+ @Override
+ protected void begin()
+ {
+ }
+
+ @Override
+ protected void end()
+ {
+ moveable.setScale(1f);
+ }
+
+ @Override
+ protected void update(float percent)
+ {
+ moveable.setScale(1 + bounceFactor * (float) Math.sin(percent * Math.PI));
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ }
+
+ @Override
+ public void drawDebug(ShapeRenderer debugShapes)
+ {
+ }
+}