loading sprites from a txt file (re factored clients)
classes modified: sprites.java
difficulty: 1/10
note: this onyl works for pngs not to hard to change either
i had a idea
instead of useing tons of if statements to load sprites why not just make a buffered reader to load the sprites name from a txt file?
so heres the boolean i made
Code:
public boolean loadSprite(String s, int i) {
try {
BufferedReader in = new BufferedReader(
new FileReader("config/loadSprites.txt"));
String data = null;
while ((data = in.readLine()) != null) {
if (s.startsWith(data) || s.equalsIgnoreCase(data)) {
try {
Image image = Toolkit.getDefaultToolkit().getImage(
"./Sprites/" + s + " " + i + ".png");
myPixels = new int[myWidth * myHeight];
PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0,
myWidth, myHeight, myPixels, 0, myWidth);
pixelgrabber.grabPixels();
// System.out.println("Sprite: "+s+" "+i+" loaded.");
} catch (Exception exception) {
System.out.println(((Object) (exception)));
}
return true;
}
}
} catch (IOException e) {
System.out.println("Critical error while checking sprites!");
e.printStackTrace();
return false;
}
return false;
}
what it does is finds the file in the folder config
checks to see if the sprite name is their
if it is their itll load the sprite from the folder sprites
if it is not their it will not load
also need to add this
Code:
if(loadSprite(s, i)) {
loadSprite(s, i);
}
in