summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-11-18 22:30:12 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2018-11-18 22:30:12 +0100
commit0deb13e7afaef61ea63f9cd518e4e858eb7ca397 (patch)
tree1962e2b29e4d7c3ddd0c2dfb7363f2d7c9bb46e0 /core/src/ch/asynk
parenta490b726204a1ce6a27e24f331f12ea563342cb0 (diff)
downloadgdx-boardgame-0deb13e7afaef61ea63f9cd518e4e858eb7ca397.zip
gdx-boardgame-0deb13e7afaef61ea63f9cd518e4e858eb7ca397.tar.gz
add FadeAnimation
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/animations/FadeAnimation.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/animations/FadeAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/FadeAnimation.java
new file mode 100644
index 0000000..90b5299
--- /dev/null
+++ b/core/src/ch/asynk/gdx/boardgame/animations/FadeAnimation.java
@@ -0,0 +1,56 @@
+package ch.asynk.gdx.boardgame.animations;
+
+import com.badlogic.gdx.utils.Pool;
+
+import ch.asynk.gdx.boardgame.Drawable;
+
+public class FadeAnimation extends TimedAnimation implements Pool.Poolable
+{
+ private static final Pool<FadeAnimation> fadeAnimationPool = new Pool<FadeAnimation>()
+ {
+ @Override protected FadeAnimation newObject()
+ {
+ return new FadeAnimation();
+ }
+ };
+
+ public static FadeAnimation obtain(Drawable drawable, float from, float to, float duration)
+ {
+ FadeAnimation a = fadeAnimationPool.obtain();
+
+ a.from = from;
+ a.to = to;
+ a.drawable = drawable;
+ a.setDuration(duration);
+
+ return a;
+ }
+
+ private float from;
+ private float to;
+ private Drawable drawable;
+
+ private FadeAnimation()
+ {
+ }
+
+ @Override public void dispose()
+ {
+ fadeAnimationPool.free(this);
+ }
+
+ @Override public void begin()
+ {
+ drawable.setAlpha(from);
+ }
+
+ @Override public void end()
+ {
+ drawable.setAlpha(to);
+ }
+
+ @Override public void update(float delta)
+ {
+ drawable.setAlpha(from + ((to - from) * percent));
+ }
+}