Skip to main content
GameDev.net gamedev.net
🔒 Locked

Loading resources location.

Started by Dennisvb Apr 13, 2013 at 9:52 PM 3 replies 1.5k views
Original Post
Dennisvb
Dennisvb
Let's say I am making a game using Slick2d and eclipse and have a file player.png which I want to load. I have 2 folders: one source folder and one resource folder. How would I do this, where should I put the resource folder?
TheChubu
TheChubu

Have you tried it?

You need your resources next to your jar, or in the case of running it from Eclipse, inside your project folder.

Say that you have a Slick2DGameProject folder, inside your resource folder, inside texture folder, and inside that a tile1.png.

You'd load it up from Java with just the relative path.


ImageBuffer img;
File fileDir = new File("resource/texture/tile1.png");
 
img = ImageIO.read(fileDir);

My loader is a static class and has a few static Strings like "String resourceDir = resource/" "String texturedir = texture/" and so on. So when I load up a file I "compose" the file location with "resourceDir + textureDir + fileName". That way you only call your loading method with the file name (fileName) and it resolves the rest of the path by itself.

I don't know if its the best way but it worked well so far (tested in Linux and Windows).

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"   My journals: dustArtemis ECS framework and 
Dennisvb
Dennisvb
Thanks for the detailed answer. I will try this out today and tell you if it worked :)!
Dennisvb
Dennisvb

Too bad, I can't figure this out. This is what I have:

5lf8nKS.png

You can also see the error I get on the bottom.

Dennisvb
Dennisvb

Got it fixed with some help from the guys at #reddit-gamdev on freenode irc. I had to type "./resources/bat.png".

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.