-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextureLoader.java
More file actions
39 lines (28 loc) · 1.24 KB
/
TextureLoader.java
File metadata and controls
39 lines (28 loc) · 1.24 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
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class TextureLoader {
public static BufferedImage wallTexture, floorTexture, spriteTexture, projectileTexture;
public static BufferedImage loadImageAsRGB(String filePath) throws IOException {
BufferedImage originalImage = ImageIO.read(new File(filePath));
if (originalImage.getType() != BufferedImage.TYPE_INT_RGB) {
BufferedImage convertedImage = new BufferedImage(
originalImage.getWidth(),
originalImage.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g = convertedImage.createGraphics();
g.drawImage(originalImage, 0, 0, null);
g.dispose();
return convertedImage;
}
return originalImage;
}
public static void init() throws IOException{
wallTexture = ImageIO.read(new File("textures/bars.png"));
floorTexture = loadImageAsRGB("textures/woodfloor.jpg");
spriteTexture = ImageIO.read((new File("textures/doomsprite.png")));
projectileTexture = ImageIO.read(new File("textures/projectile.png"));
}
}