-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnimatedSprite.pde
50 lines (46 loc) · 1.18 KB
/
AnimatedSprite.pde
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
public class AnimatedSprite extends Sprite {
PImage[] currentImg;
PImage[] stand;
PImage[] move;
int facing;
int index;
int frame;
public AnimatedSprite (PImage image, int size_x, int size_y, float x, float y) {
super(image, size_x,size_y, x ,y);
facing = MIDDLE_FACING;
index = 0;
frame = 0;
}
public void updateAnimation() {
frame++;
if (frame % 9 == 0) {
selectImg();
moveToNextImg();
}
}
public void selectImg() {
if (change_x != 0) {
currentImg = move;
}
else {
currentImg = stand;
}
}
public void moveToNextImg() {
index = (index + 1) % currentImg.length;
image = currentImg[index];
}
void loadFrames(PImage[] ar, String fname) {
for (int i=0; i<ar.length; i++) {
PImage frame=loadImage(fname+(i+1)+".png");
ar[i]=frame;
}
}
public void setFrames(int size, String name) {
if (name.equals("stand")) {
stand = new PImage[size];
} else if (name.equals("move")) {
move = new PImage[size];
}
}
}