-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpriteSheet.java
More file actions
44 lines (36 loc) · 1.37 KB
/
SpriteSheet.java
File metadata and controls
44 lines (36 loc) · 1.37 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
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class SpriteSheet {
private BufferedImage image;
private BufferedImage[][] sprites;
private int width, height;
public SpriteSheet(String pSpriteSheetPath, int pDirections, int pMoves) {
// int pTile.TILEWIDTH, int pTile.TILEHEIGHT
sprites = new BufferedImage[pDirections][pMoves];
//Create Sprites:
try {
image = ImageIO.read(new File(pSpriteSheetPath));
width = image.getWidth() / pMoves;
height = image.getHeight() / pDirections;
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Ungültiges Spritesheet auf dem Pfad : " + pSpriteSheetPath, "", JOptionPane.WARNING_MESSAGE);
} // end of try
for (int direction = 0; direction < pDirections; direction++) {
for (int move = 0; move < pMoves; move++) {
sprites[direction][move] = image.getSubimage(move * width, direction * height, width, height);
} // end of for
} // end of for
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public BufferedImage getSpriteElement(int pDirection, int pMove) {
return sprites[pDirection][pMove];
}
}