forked from hajarhesham/SuperCube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimatedSprite.pde
57 lines (46 loc) · 1.06 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
51
52
53
54
55
56
57
public class AnimatedSprite extends Sprite{
PImage[] currentImages;
PImage[] standNeutral;
PImage[] moveLeft;
PImage[] moveRight;
int direction;
int index;
int frame;
public AnimatedSprite(PImage img, float scale){
super(img,scale);
direction = NEUTRAL_FACING;
index = 0;
frame = 0;
}
public void updateAnimation(){
frame++;
if(frame % 5 == 0 ){
selectDirection();
selectCurrentImages();
advanceToNextImage();
}
}
public void selectDirection(){
if(change_x > 0){
direction = RIGHT_FACING;
}
else if(change_x < 0){
direction = LEFT_FACING;
}
else{
direction = NEUTRAL_FACING;
}}
public void selectCurrentImages(){
if(direction == RIGHT_FACING)
currentImages = moveRight;
else if(direction == LEFT_FACING)
currentImages = moveLeft;
else
currentImages = standNeutral;
}
public void advanceToNextImage(){
index++;
if(index >= currentImages.length) index=0;
image = currentImages[index];
}
}