-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.java
More file actions
35 lines (30 loc) · 839 Bytes
/
Copy pathAnimation.java
File metadata and controls
35 lines (30 loc) · 839 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
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import java.time.*;
public class Animation {
Clock clock = Clock.systemDefaultZone();
int currFrame;
long lastTime = 0;
int timeBetweenFrames = 150;
BufferedImage frame;
private List<BufferedImage> frameList;
public BufferedImage getFrame(){
return frameList.get(currFrame);
}
public Animation(){
frameList = new ArrayList<BufferedImage>();
}
public void addFrame(BufferedImage frame){
frameList.add(frame);
}
public void updateFrame(){
if(clock.millis() > lastTime+timeBetweenFrames) {
currFrame++;
if (currFrame >= frameList.size()) {
currFrame = 0;
}
lastTime = clock.millis();
}
}
}