If I want to use the PackedSpriteSheet , I have to pass a String. There is no constructor that takes an URL.
So I only can use it that way
Code:
spriteSheet = new PackedSpriteSheet(GameOne.class.getResource(defPath)
.getPath());
But when I use it like that, there comes an error prompt "Resource not found"?!
UPDATE:
I found an really ugly workaround.
I modified the PacketSpriteSheet.class and hardcoded the resource loading part. But it doesn't matter for me. I only wanted to fix it as fast as possible.
Code:
private void loadDefinition(String def, Color trans) throws SlickException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
PackedSpriteSheet.class
.getResourceAsStream("game_one_spritesheet.def")));
try {
image = new Image(
PackedSpriteSheet.class
.getResourceAsStream("game_one_spritesheet.png"),
"", false);
reader.readLine();
while (reader.ready()) {
if (reader.readLine() == null) {
break;
}
Section sect = new Section(reader);
sections.put(sect.name, sect);
if (reader.readLine() == null) {
break;
}
}
} catch (Exception e) {
Log.error(e);
throw new SlickException(
"Failed to process definitions file - invalid format?", e);
}
}
And I copied the files I had to load in the same package as the modified PacketSpriteSheet.class.
Now it loads without errors
