-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimatedActor.java
More file actions
49 lines (42 loc) · 1.24 KB
/
AnimatedActor.java
File metadata and controls
49 lines (42 loc) · 1.24 KB
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
import processing.core.PImage;
import java.util.List;
public abstract class AnimatedActor
extends Actor
{
private int animation_rate;
public AnimatedActor(String name, Point position, int rate,
int animation_rate, List<PImage> imgs)
{
super(name, position, rate, imgs);
this.animation_rate = animation_rate;
}
public int getAnimationRate()
{
return this.animation_rate;
}
public void schedule(WorldModel world, long time, ImageStore imageStore)
{
super.schedule(world, time, imageStore);
scheduleAnimation(world);
}
protected void scheduleAnimation(WorldModel world)
{
Actor.scheduleAction(world, this, createAnimationAction(world, 0),
animation_rate);
}
protected Action createAnimationAction(WorldModel world, int repeatCount)
{
Action action[] = { null };
action[0] = currentTime -> {
this.removePendingAction(action[0]);
this.nextImage();
if (repeatCount != 1)
{
Actor.scheduleAction(world, this,
createAnimationAction(world, Math.max(repeatCount - 1, 0)),
currentTime + animation_rate);
}
};
return action[0];
}
}