blob: 90b5299415d71f4cdf463e18e39556b30342790e (
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
|
package ch.asynk.gdx.boardgame.animations;
import com.badlogic.gdx.utils.Pool;
import ch.asynk.gdx.boardgame.Drawable;
public class FadeAnimation extends TimedAnimation implements Pool.Poolable
{
private static final Pool<FadeAnimation> fadeAnimationPool = new Pool<FadeAnimation>()
{
@Override protected FadeAnimation newObject()
{
return new FadeAnimation();
}
};
public static FadeAnimation obtain(Drawable drawable, float from, float to, float duration)
{
FadeAnimation a = fadeAnimationPool.obtain();
a.from = from;
a.to = to;
a.drawable = drawable;
a.setDuration(duration);
return a;
}
private float from;
private float to;
private Drawable drawable;
private FadeAnimation()
{
}
@Override public void dispose()
{
fadeAnimationPool.free(this);
}
@Override public void begin()
{
drawable.setAlpha(from);
}
@Override public void end()
{
drawable.setAlpha(to);
}
@Override public void update(float delta)
{
drawable.setAlpha(from + ((to - from) * percent));
}
}
|