How do I load tmx files with Slick2d?

Posted by mbreen on Game Development See other posts from Game Development or by mbreen
Published on 2012-04-29T17:21:03Z Indexed on 2012/10/16 17:22 UTC
Read the original article Hit count: 413

Filed under:
|

I just started using Slick2D and learned how simple it is to load in a tilemap and display it. I tried atleast a dozen different tmx files from numerous examples to see if it was the actual file that was corrupted. Everytime I get this error:

Exception in thread "main" java.lang.RuntimeException: Resource not found: data/maps/desert.tmx
    at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
    at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:101)
    at game.Game.init(Game.java:17)
    at game.Tunneler.initStatesList(Tunneler.java:37)
    at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:164)
    at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
    at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
    at game.Tunneler.main(Tunneler.java:29)

Here is my Game class:

package game;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.tiled.TiledMap;

public class Game extends BasicGameState{
    private int stateID = -1;
    private TiledMap map = null;

    public Game(int stateID){
        this.stateID = stateID;
    }
    public void init(GameContainer container, StateBasedGame game) throws SlickException{
        map = new TiledMap("data/maps/desert.tmx","maps");//ERROR
    }
    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException{
        //map.render(0,0);
    }
    public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException{
    }

    public int getID(){return stateID;}
}

I've tried to see if anyone else has had similar problems but haven't turned up anything. I am able to load other files, so I don't believe it's a compiler issue. My menu class can load images and display them just fine. Also, the filepath is correct.

Please let me know if you have any pointers that might help me sort this out.

© Game Development or respective owner

Related posts about java

Related posts about slick