-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimatedImage.java
More file actions
40 lines (34 loc) · 977 Bytes
/
AnimatedImage.java
File metadata and controls
40 lines (34 loc) · 977 Bytes
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
import processing.core.PApplet;
import processing.core.PImage;
/***
* Displays an animated image.
*
* @author David (modified from example on processing.org)
*/
public class AnimatedImage {
PImage[] images;
int imageCount;
int frame = 0;
public boolean finishedFirstLoop = false;
PApplet p;
public AnimatedImage(PApplet p, String filepath, String imagePrefix, String imageSuffix, int count, int x, int y) {
imageCount = count;
images = new PImage[imageCount];
this.p = p;
for (int i = 0; i < imageCount; i++) {
String filename = filepath + imagePrefix + i + imageSuffix + ".gif";
images[i] = p.loadImage(filename);
images[i].resize(x, y);
}
}
public void display(float xpos, float ypos) {
if(frame == imageCount-1) finishedFirstLoop = true;
p.image(images[frame], xpos, ypos);
}
public void tick(){
frame = (frame+1) % imageCount;
}
public int getWidth() {
return images[0].width;
}
}