-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpriteSheet.java
More file actions
56 lines (43 loc) · 1.41 KB
/
SpriteSheet.java
File metadata and controls
56 lines (43 loc) · 1.41 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
50
51
52
53
54
55
56
import java.awt.image.BufferedImage;
public class SpriteSheet {
BufferedImage[] frameArray;
int frames;
int currentFrameCount;
int frameDelay;
boolean playedOnce = false;
boolean isChecking;
public SpriteSheet(BufferedImage input, int aFrames) {
frames = aFrames;
boolean playedOnce = false;
currentFrameCount = 0;
frameDelay = 1;
isChecking = false;
frameArray = new BufferedImage[frames];
for (int i = 0; i < frames; i++) {
frameArray[i] = input.getSubimage(i * (input.getWidth() / frames), 0, (input.getWidth() / frames),
input.getHeight());
}
}
public BufferedImage loop() {
currentFrameCount++;
if (this.currentFrameCount / (frames * frameDelay) == 1 && isChecking) {
playedOnce = true;
} else {
playedOnce = false;
}
currentFrameCount %= (frameDelay * frames);
if (frameDelay == 11) {
// System.out.println(currentFrameCount + ":" + frames + ":" + frameDelay + ":"
// + Main.spikesheet.currentFrameCount/frameDelay);
}
return frameArray[currentFrameCount / frameDelay];
}
// loop will return the current frame and then move onto the next one
// will need a boolean to make it only loop once so a condition setter
// if the loop has played the last frame was played and if so, set playedOnce to
// true
// else set it to false
public void changeFrameDelayTo(int input) {
frameDelay = input;
}
}