4
\$\begingroup\$

How I can import and draw a tilemap with different layers? I have the next code and send me error if the tilemap have more than one layer.

public class Map {

    private TiledMap map = null;

    private int bg,level,extras;

    public void init(GameContainer container) throws SlickException {

        map = new TiledMap("assets/levels/default.tmx", false);

    }

    public void render(int type, GameContainer container, Graphics g) {

//      map.render(0, 0, 0, 0, 19, 13);

    }

    public void update(GameContainer container, int delta) {}

}

I was thinking to save each layer in a different variable for later draw each layer. But Im not sure how I can do it. I have been looking for tutorials, and the slick2d API. And this is the error.

Fri Feb 06 22:18:30 GMT 2015 ERROR:For input string: ""
java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at org.newdawn.slick.tiled.TiledMap$ObjectGroup.<init>(TiledMap.java:1008)
    at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:688)
    at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:106)
    at gameEngine.Map.init(Map.java:54)
    at states.Play.init(Play.java:26)
    at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
    at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
    at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
    at gameEngine.Main.main(Main.java:31)
Fri Feb 06 22:18:30 GMT 2015 ERROR:Failed to parse tilemap
org.newdawn.slick.SlickException: Failed to parse tilemap
    at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:695)
    at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:106)
    at gameEngine.Map.init(Map.java:54)
    at states.Play.init(Play.java:26)
    at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
    at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
    at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
    at gameEngine.Main.main(Main.java:31)
Caused by: java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at org.newdawn.slick.tiled.TiledMap$ObjectGroup.<init>(TiledMap.java:1008)
    at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:688)
    ... 7 more
\$\endgroup\$
2
  • \$\begingroup\$ A bit more on the actual error it's giving would help. I'm looking at the slick2D api and i don't see any mention of the Layer class in your current code. A sample that includes you using the layers or the code that gives you the error would help too. \$\endgroup\$ – Coburn Feb 6 '15 at 21:14
  • \$\begingroup\$ The problem is when you try to load a Tilemap with more then one layer. Always the line error is " map = new TiledMap("assets/levels/default.tmx", false); ". And if the tilemap have only one layer, loads the file without any problem. \$\endgroup\$ – Jota_sk Feb 6 '15 at 22:21
1
\$\begingroup\$

You should probably be using LibGDX. Slick2d is no longer under active development. I had the same problem, and it was solved by switching to LibGDX, which has an updated version of the Tiled Map support classes that were started in Slick2d.

\$\endgroup\$
0
\$\begingroup\$

I found a discrepancy between the Tiled Map Editor and the nature of the int data type. When in an object layer, you must make sure each of the objects have no decimal values, either in their width, height, X, or Y location. Because an int cannot support decimal values (you could edit slick's code to support a double data type if you needed a decimal value) the parseInt method throws that error. The simple fix I did was to make sure all of those values were in increments of my tiles, which also fixed the problem.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.