summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/gdx/boardgame')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java4
-rw-r--r--core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java36
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;
}
}