From 01093ee759f5cf9f9c260fa9ef61b87201fe7130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 14 Nov 2018 00:18:27 +0100 Subject: =?UTF-8?q?TimedAnimation=20:=20add=20float=20elapsed=20parameter?= =?UTF-8?q?=20to=20update(=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java | 2 +- core/src/ch/asynk/gdx/boardgame/animations/DelayAnimation.java | 2 +- core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java index cd4f3aa..cda604c 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java @@ -72,7 +72,7 @@ public class BounceAnimation extends TimedAnimation implements Pool.Poolable } } - @Override protected void update(float percent) + @Override protected void update(float elapsed, float percent) { piece.setScale(this.startScale + this.bounceFactor * (float) Math.sin(percent * Math.PI)); if (rotationDegrees != 0f) { diff --git a/core/src/ch/asynk/gdx/boardgame/animations/DelayAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/DelayAnimation.java index 695a21a..4ce6097 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/DelayAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/DelayAnimation.java @@ -43,7 +43,7 @@ public class DelayAnimation extends TimedAnimation implements Pool.Poolable @Override protected void begin() { } @Override protected void end() { } - @Override protected void update(float percent) { } + @Override protected void update(float elapsed, float percent) { } @Override public void draw(Batch batch) { diff --git a/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java index 3d35dd9..3f351d2 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java @@ -6,10 +6,11 @@ public abstract class TimedAnimation implements Animation { private float dp; private float percent; + private float elapsed; abstract protected void begin(); abstract protected void end(); - abstract protected void update(float percent); + abstract protected void update(float elapsed, float percent); public void setDuration(float duration) { @@ -19,6 +20,7 @@ public abstract class TimedAnimation implements Animation public void reset() { percent = 0f; + elapsed = 0f; } @Override public boolean completed() @@ -32,7 +34,8 @@ public abstract class TimedAnimation implements Animation begin(); } - percent += (dp * delta); + elapsed += delta; + percent = (dp * elapsed); if (percent >= 1f) { // percent = 1f; @@ -40,7 +43,7 @@ public abstract class TimedAnimation implements Animation end(); return true; } else { - update(percent); + update(elapsed, percent); return false; } } -- cgit v1.1-2-g2b99