0

I can't figure out how to load textures in a 2d environment using lwjgl.

I'm using their tutorial's Sprite, Texture and TextureLoader classes. I've simply replaced the original paths/files with my own, which I've checked to make sure are correct about 20 times. Here's the code, and the error it produces.

public Sprite(TextureLoader loader, String ref) {
    try 
    {
        texture = loader.getTexture("C:/Users/John/workspace/MyGames/sprites/" + ref);
        width = texture.getImageWidth();
        height = texture.getImageHeight();
    } 
    catch (IOException ioe) 
    {
        ioe.printStackTrace();
        System.exit(-1);
    }
}


java.io.IOException: Cannot find: C:/Users/John/workspace/MyGames/sprites/ship.gif

What am I doing wrong?

Edit: When I try to run the lwgjl space invaders game on its own with no modifications I get the same problem. I have all the files in the correct path and have checked that the paths exist within the call.

JohnF
  • 339
  • 4
  • 11
  • 2
    Add `System.out.println(new File(path).exists())` before `getTexture`, to make sure it's the correct path. Try replacing `/` with \\. Which `TextureLoader` are you using? – Piotr Praszmo Sep 24 '12 at 16:19
  • The System.out line prints true. I tried the escape method already to no avail. I'm using the TextureLoader class from the lwjgl tutorial: [link](http://www.lwjgl.org/wiki/index.php?title=Examples:SpaceInvaders_TextureLoader) – JohnF Sep 24 '12 at 19:03
  • I have copied your code and have the same issue. Have you tried using Slick-util for texture loading? – Coupon22 Sep 24 '12 at 21:23
  • I took your suggestion and things seem to be working now, thanks! – JohnF Sep 24 '12 at 22:25

0 Answers0