diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-14 13:06:27 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-14 13:06:27 +0200 |
commit | 9bd9fb592a3daaab1033e63b2202403da9517e4e (patch) | |
tree | d2c9a8ef92b9e771c3a0f165309ebb5ce59142be | |
parent | 035e3825c8c9b0679e753b6e4ec3650777381f36 (diff) | |
download | gdx-boardgame-9bd9fb592a3daaab1033e63b2202403da9517e4e.zip gdx-boardgame-9bd9fb592a3daaab1033e63b2202403da9517e4e.tar.gz |
animations : clean up
TimedAnimation does not implement Pool.Poolable,
BounceAnimation and DelayAnnimation do.
remove all drawDebug stuff
5 files changed, 40 insertions, 28 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/animations/AnimationSequence.java b/core/src/ch/asynk/gdx/boardgame/animations/AnimationSequence.java index 88bb15b..8aa6b06 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/AnimationSequence.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/AnimationSequence.java @@ -2,7 +2,6 @@ package ch.asynk.gdx.boardgame.animations; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.gdx.boardgame.utils.IterableArray; @@ -76,9 +75,4 @@ public class AnimationSequence implements Animation, Pool.Poolable animations.get(0).draw(batch); } } - - @Override public void drawDebug(ShapeRenderer debugShapes) - { - animations.get(0).drawDebug(debugShapes); - } } diff --git a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java index 271728c..432d0d7 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java @@ -4,11 +4,10 @@ import java.lang.Math; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.gdx.boardgame.pieces.Piece; -public class BounceAnimation extends TimedAnimation +public class BounceAnimation extends TimedAnimation implements Pool.Poolable { private static final Pool<BounceAnimation> bounceAnimationPool = new Pool<BounceAnimation>() { @@ -40,14 +39,6 @@ public class BounceAnimation extends TimedAnimation { } - public BounceAnimation(Piece piece, float duration, float bounceFactor, int rotations) - { - this.piece = piece; - this.bounceFactor = bounceFactor; - this.setDuration(duration); - this.computeRotationDegrees(rotations); - } - private void computeRotationDegrees(int rotations) { if (rotations == 0) { @@ -57,6 +48,11 @@ public class BounceAnimation extends TimedAnimation } } + @Override public void reset() + { + super.reset(); + } + @Override public void dispose() { bounceAnimationPool.free(this); @@ -88,8 +84,4 @@ public class BounceAnimation extends TimedAnimation { piece.draw(batch); } - - @Override public void drawDebug(ShapeRenderer debugShapes) - { - } } diff --git a/core/src/ch/asynk/gdx/boardgame/animations/DelayAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/DelayAnimation.java index 8baa9b1..0d20cae 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/DelayAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/DelayAnimation.java @@ -1,23 +1,49 @@ package ch.asynk.gdx.boardgame.animations; +import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.graphics.g2d.Batch; import ch.asynk.gdx.boardgame.Drawable; -public class DelayAnimation extends TimedAnimation +public class DelayAnimation extends TimedAnimation implements Pool.Poolable { + private static final Pool<DelayAnimation> delayAnimationPool = new Pool<DelayAnimation>() + { + @Override protected DelayAnimation newObject() + { + return new DelayAnimation(); + } + }; + + public static DelayAnimation get(Drawable drawable, float duration) + { + DelayAnimation a = delayAnimationPool.obtain(); + + a.drawable = drawable; + a.setDuration(duration); + + return a; + } + private Drawable drawable; - public DelayAnimation(Drawable drawable, float duration) + private DelayAnimation() + { + } + + @Override public void reset() + { + super.reset(); + } + + @Override public void dispose() { - this.drawable = drawable; - setDuration(duration); + delayAnimationPool.free(this); } @Override protected void begin() { } @Override protected void end() { } @Override protected void update(float percent) { } - @Override public void dispose() { } @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 9540507..3d35dd9 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/TimedAnimation.java @@ -2,7 +2,7 @@ package ch.asynk.gdx.boardgame.animations; import com.badlogic.gdx.utils.Pool; -public abstract class TimedAnimation implements Animation, Pool.Poolable +public abstract class TimedAnimation implements Animation { private float dp; private float percent; @@ -16,7 +16,7 @@ public abstract class TimedAnimation implements Animation, Pool.Poolable dp = 1f / duration; } - @Override public void reset() + public void reset() { percent = 0f; } diff --git a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java index caeabda..fc8f0c1 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java @@ -43,7 +43,7 @@ public class AnimationsScreen extends AbstractScreen animations = AnimationSequence.get(10); animations.add(BounceAnimation.get(panzer, 2f, 3f, -1)); - animations.add(new DelayAnimation(panzer, 1f)); + animations.add(DelayAnimation.get(panzer, 1f)); } @Override public void dispose() |