-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpriteAnimations.java
More file actions
42 lines (36 loc) · 1.2 KB
/
Copy pathSpriteAnimations.java
File metadata and controls
42 lines (36 loc) · 1.2 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
import java.awt.Graphics2D;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class SpriteAnimations
{
public static BufferedImage loadSprite(String file) {
BufferedImage sprite = null;
try {
sprite = ImageIO.read(new File(file + ".png"));
} catch (IOException e) {
e.printStackTrace();
}
return sprite;
}
public static BufferedImage getSprite(BufferedImage sheet,int xGrid, int yGrid) {
int TILE_SIZEY = sheet.getWidth()/3;
int TILE_SIZEX = sheet.getHeight()/4;
return sheet.getSubimage(yGrid * TILE_SIZEY,xGrid * TILE_SIZEX , TILE_SIZEY, TILE_SIZEX);
}
public static BufferedImage[] createSprite(String file){
BufferedImage f = loadSprite(file);
BufferedImage[] out = new BufferedImage[16];
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
if (j%2 == 0){
out[4*i+j] = getSprite(f, i, 1);
} else {
out[4*i+j] = getSprite(f,i,(j-1)%3);
}
}
}
return out;
}
}