diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-11 15:25:11 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-11 15:25:11 +0200 |
commit | 519ad40a1703ef064a068ab0cd759d62c72d09e1 (patch) | |
tree | d3abef219bf6d43637c2f1bd252f55fe4617accb /core/src/ch/asynk | |
parent | f13fd322aec790641cd61be3b009d4ae8154e67e (diff) | |
download | gdx-boardgame-519ad40a1703ef064a068ab0cd759d62c72d09e1.zip gdx-boardgame-519ad40a1703ef064a068ab0cd759d62c72d09e1.tar.gz |
TimedAnimation : optimize
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java | 36 |
2 files changed, 19 insertions, 21 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java index cd99fb0..22aa470 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java @@ -23,8 +23,8 @@ public class BounceAnimation extends TimedAnimation BounceAnimation a = bounceAnimationPool.obtain(); a.piece = piece; - a.duration = duration; a.bounceFactor = bounceFactor; + a.setDuration(duration); return a; } @@ -39,8 +39,8 @@ public class BounceAnimation extends TimedAnimation public BounceAnimation(Piece piece, float duration, float bounceFactor) { this.piece = piece; - this.duration = duration; this.bounceFactor = bounceFactor; + this.setDuration(duration); } @Override public void dispose() diff --git a/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java index f66cb98..9540507 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java @@ -4,46 +4,44 @@ import com.badlogic.gdx.utils.Pool; public abstract class TimedAnimation implements Animation, Pool.Poolable { - private float time; - private boolean started; - private boolean completed; - protected float duration; + private float dp; + private float percent; abstract protected void begin(); abstract protected void end(); abstract protected void update(float percent); + public void setDuration(float duration) + { + dp = 1f / duration; + } + @Override public void reset() { - time = 0f; - started = false; - completed = false; + percent = 0f; } @Override public boolean completed() { - return completed; + return (percent >= 1f); } @Override public boolean animate(float delta) { - if (completed) return true; - - if (!started) { + if (percent == 0) { begin(); - started = true; } - time += delta; + percent += (dp * delta); - if (time >= duration) { - completed = true; - update(1); + if (percent >= 1f) { + // percent = 1f; + // update(percent); end(); + return true; } else { - update(time / duration); + update(percent); + return false; } - - return completed; } } |