From 6859800c15183cc1669285635778269c52df662b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 31 Mar 2016 14:32:30 +0200 Subject: add engine/gfx/animations/BounceAnimation --- .../engine/gfx/animations/BounceAnimation.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java 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 bounceAnimationPool = new Pool() { + @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) + { + } +} -- cgit v1.1-2-g2b99