diff options
Diffstat (limited to 'core/src/ch/asynk/gdx/boardgame')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/animations/AnimationBatch.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/animations/AnimationBatch.java b/core/src/ch/asynk/gdx/boardgame/animations/AnimationBatch.java new file mode 100644 index 0000000..617238a --- /dev/null +++ b/core/src/ch/asynk/gdx/boardgame/animations/AnimationBatch.java @@ -0,0 +1,82 @@ +package ch.asynk.gdx.boardgame.animations; + +import com.badlogic.gdx.utils.Pool; +import com.badlogic.gdx.graphics.g2d.Batch; + +import ch.asynk.gdx.boardgame.utils.IterableArray; + +public class AnimationBatch implements Animation, Pool.Poolable +{ + private static final Pool<AnimationBatch> animationBatchPool = new Pool<AnimationBatch>() + { + @Override protected AnimationBatch newObject() + { + return new AnimationBatch(); + } + }; + + public static AnimationBatch obtain(int capacity) + { + AnimationBatch batch = animationBatchPool.obtain(); + if (batch.animations == null) { + batch.animations = new IterableArray<Animation>(capacity); + } else { + batch.animations.ensureCapacity(capacity); + } + + return batch; + } + + private IterableArray<Animation> animations; + + private AnimationBatch() + { + } + + @Override public void reset() + { + for (Animation a : animations) { + a.dispose(); + } + animations.clear(); + } + + @Override public void dispose() + { + animationBatchPool.free(this); + } + + public void add(Animation animation) + { + animations.add(animation); + } + + @Override public boolean completed() + { + return animations.isEmpty(); + } + + @Override public boolean animate(float delta) + { + if (!completed()) { + System.err.println("paralel"); + for (Animation animation : animations) { + if (animation.animate(delta)) { + animations.remove(animation); + animation.dispose(); + } + } + } + + return completed(); + } + + @Override public void draw(Batch batch) + { + if (!completed()) { + for (Animation animation : animations) { + animation.draw(batch); + } + } + } +} |