0
votes

I've got a question, I verly new to slick and I'm making a sidescroller. I'm trying to load a spritesheet in a stateBasedGame. But when i run/debug the game it runs but doesn't show the image. Here is the code:

//private static Map<String, Image> images;
private static Map<String, SpriteSheet> sprites;
//private static Map<String, Sound> sounds;

public Resources() {
    //images = new HashMap<String, Image>();
    sprites = new HashMap<String, SpriteSheet>();
    //sounds = new HashMap<String, Sound>();

    try {
        sprites.put("tiles", loadSprite("resources/tiles.png", 32, 32));
    } catch (SlickException e) {
        e.printStackTrace();
    }
}

private Image loadImage(String path) throws SlickException {
    return new Image(path, false, Image.FILTER_NEAREST);
}

private SpriteSheet loadSprite(String path, int tw, int th) throws SlickException {
    return new SpriteSheet(loadImage(path), tw, th);
}

public static Image getSpriteImage(String getter, int x, int y) {
    sprites.get(getter).getSubImage(x, y);
    return null;
}

and in the GameState I put this:

Resources.getSpriteImage("tiles", 0, 0);

I double checked the path and that is correct. Please help me!

2

2 Answers

0
votes

It's correct, the issue is you're not calling the draw method, you're only getting an instance of the image.

Try this: Resources.getSpriteImage("tiles", 0, 0).draw(0, 0);

0
votes

Your method getSpriteImage needs to return the image instead of returning null:

public static Image getSpriteImage(String getter, int x, int y) {
    return sprites.get(getter).getSubImage(x, y);
}

And don't forget to actually draw the tile in your GameState:

Resources.getSpriteImage("tiles", 0, 0).draw(0, 0);