blob: 08091d2b795afb2094ac010c5e7caa5134275ce0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
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;
public class AnimationSequence implements Animation, Pool.Poolable
{
private static final Pool<AnimationSequence> animationSequencePool = new Pool<AnimationSequence>()
{
@Override protected AnimationSequence newObject()
{
return new AnimationSequence();
}
};
public static AnimationSequence obtain(int capacity)
{
AnimationSequence seq = animationSequencePool.obtain();
if (seq.animations == null) {
seq.animations = new IterableArray<Animation>(capacity);
} else {
seq.animations.ensureCapacity(capacity);
}
return seq;
}
private IterableArray<Animation> animations;
private AnimationSequence()
{
}
@Override public void reset()
{
for (Animation a : animations) {
a.dispose();
}
animations.clear();
}
@Override public void dispose()
{
animationSequencePool.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()) {
Animation animation = animations.get(0);
if (animation.animate(delta)) {
animations.remove(0);
animation.dispose();
}
}
return completed();
}
@Override public void draw(Batch batch)
{
if (!completed()) {
animations.get(0).draw(batch);
}
}
@Override public void drawDebug(ShapeRenderer shapeRenderer)
{
if (!completed()) {
animations.get(0).drawDebug(shapeRenderer);
}
}
}
|