diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-11-14 00:27:24 +0100 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-11-14 00:27:24 +0100 | 
| commit | 86d48ada8feb5810fd745433469442bc03316267 (patch) | |
| tree | 49f7faf6cb9412e353fd0a796638b126fe169693 /core | |
| parent | 01093ee759f5cf9f9c260fa9ef61b87201fe7130 (diff) | |
| download | gdx-boardgame-86d48ada8feb5810fd745433469442bc03316267.zip gdx-boardgame-86d48ada8feb5810fd745433469442bc03316267.tar.gz | |
add AnimationBatch
Diffstat (limited to 'core')
| -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); +            } +        } +    } +} | 
