Texture Loader

This is probably very obvious but any help would be appreciated:

when using TextureLoader i have to specify the exact path that contains the image i’m trying to load,
otherwise i just get ‘Error loading image back.jpg’
This will be a pain when i have to upload onto a server and change all the paths.
I’ve looked at lots of forums and tryed many ways of using the textureloader to no avail.

Appearance wallAppearance(){
String filename = (“c:/new folder/back.jpg”);
Appearance appearance = new Appearance();
TextureLoader myLoader = new TextureLoader(filename, this);
Texture brick = myLoader.getTexture();
appearance.setTexture(brick);
return appearance;
}

my image is in the same folder as my code and i have seen lots of examples where just the filename
is specified, is there something i am missing?

hi!
May be the filepath is wrong:
for example:using the “C:\images\pic.jpg”;
you can have a try;
of course ,you can use the code bellow:
this.getClass().getResource("/images/pic.jpg");
Just ,the images filedirc is in your package;
ok>!

In general, you should probably use java.io.File.Separator instead of hardcoded forward-slash and back-slash, especially if you want to retain cross-platform capability.

Also, you will want to keep your drive letter and base directory path separate, so you don’t have to change the hardcoded names everywhere. You can just change them in one place. Or, better yet, read them from a properties file or from the start-up command.

e.g.


import java.io.File;

...

String baseDrive = "C:";
String basePath = "mygame";

String filename = baseDrive + File.Separator + basePath + "images" + File.Separator + "back.jpg"; 


So, on your PC, it might be:
C:\mygame\images\back.jpg

On the Linux server, it could be something like:
/home/dude/gameserver/images/back.jpg