-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextureAtlas.java
56 lines (42 loc) · 1.72 KB
/
TextureAtlas.java
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 TextureAtlas {
public static final TextureAtlas overworldTextures = SpriteLoader.loadTextureAtlas(
"images/Overworld.png",
16, 16);
public static final TextureAtlas objectTextures = SpriteLoader.loadTextureAtlas(
"images/objects.png",
16, 16);
public static final TextureAtlas caveTextures = SpriteLoader.loadTextureAtlas(
"images/cave.png",
16, 16);
public static final TextureAtlas characterTextures = SpriteLoader.loadTextureAtlas(
"images/character.png",
16, 16);
public static final TextureAtlas innerTextures = SpriteLoader.loadTextureAtlas(
"images/Inner.png",
16, 16);
BufferedImage image;
BufferedImage[][] textures;
private int tileWidth;
private int tileHeight;
public TextureAtlas(BufferedImage image, int tileWidth, int tileHeight) {
this.image = image;
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
textures = new BufferedImage[image.getWidth() / tileWidth][image.getHeight() / tileHeight];
}
public BufferedImage getTile(int tileX, int tileY) {
if (textures[tileX][tileY] == null)
textures[tileX][tileY] = image.getSubimage(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight);
return textures[tileX][tileY];
}
public BufferedImage getTile(int tileX, int tileY, int tileWidth, int tileHeight) {
return image.getSubimage(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight);
}
public int getTileWidth() {
return tileWidth;
}
public int getTileHeight() {
return tileHeight;
}
}