-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.java
More file actions
78 lines (68 loc) · 2.1 KB
/
Copy pathAnimation.java
File metadata and controls
78 lines (68 loc) · 2.1 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import mayflower.*;
/**
* @author suhas
* A class that helps to animate a character, using a list of MayflowerImages, and a set framerate to shift images at
*/
public class Animation {
// private int framerate;
private final MayflowerImage[] frames;
private int currentFrame;
/**
* Initialize an animation
* @param fr the framerate the animation runs at
* @param fns a list of filenames of your animation (used to fetch the images for the MayflowerImages)
*/
public Animation(int fr, String[] fns) {
frames = new MayflowerImage[fns.length];
for (int i = 0; i < fns.length; i++) {
frames[i] = new MayflowerImage(fns[i]);
}
currentFrame = 0;
}
// private int getFramerate() { return framerate; }
// Switch to the next frame, and if the new frame is more than the total # of frames, go back to frame 0
// and return the new frame
public MayflowerImage getNextFrame() {
MayflowerImage re = frames[currentFrame];
currentFrame += 1;
currentFrame %= frames.length;
return re;
}
/**
* Scale every image in the Animation
* @param w width to be scaled to
* @param h height to be scaled to
*/
public void scale(int w, int h) {
for (MayflowerImage frame : frames) {
frame.scale(w, h);
}
}
/**
* Set the transparency of every image in the Animation
* @param percent % transparency to set to
*/
public void setTransparency(int percent) {
for (MayflowerImage frame : frames) {
frame.setTransparency(percent);
}
}
// Flip every image in an animation
public void mirrorHorizontally() {
for (MayflowerImage frame : frames) {
frame.mirrorHorizontally();
}
}
/**
* bulk crop every image
* @param x x coordinate
* @param y y coordinate
* @param w width
* @param h height
*/
public void setBounds(int x, int y, int w, int h) {
for (MayflowerImage frame : frames) {
frame.crop(x, y, w, h);
}
}
}