From 0deb13e7afaef61ea63f9cd518e4e858eb7ca397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 18 Nov 2018 22:30:12 +0100 Subject: add FadeAnimation --- .../gdx/boardgame/animations/FadeAnimation.java | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 core/src/ch/asynk/gdx/boardgame/animations/FadeAnimation.java 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 fadeAnimationPool = new Pool() + { + @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)); + } +} -- cgit v1.1-2-g2b99