From 86d48ada8feb5810fd745433469442bc03316267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 14 Nov 2018 00:27:24 +0100 Subject: add AnimationBatch --- .../gdx/boardgame/animations/AnimationBatch.java | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 core/src/ch/asynk/gdx/boardgame/animations/AnimationBatch.java 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 animationBatchPool = new Pool() + { + @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(capacity); + } else { + batch.animations.ensureCapacity(capacity); + } + + return batch; + } + + private IterableArray 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); + } + } + } +} -- cgit v1.1-2-g2b99