Reputation: 1116
I'm trying to load a simple map made by Tiled inside my Android studio project. I'm using libGDX to made a simple platform game. In Tiled I've just imported a tileset, created a platform and anything else.
Now I would like to understand in the witch part that I am failing my upload because I am not able to understand why I have this error:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error parsing file: mapassets.json
at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:83)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.getDependencyFileHandles(TmxMapLoader.java:116)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:74)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:59)
at com.arcadan.push_the_player.TiledTest.create(TiledTest.java:28)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:150)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:127)
Caused by: com.badlogic.gdx.utils.SerializationException: Error parsing XML on line 1 near:
{ "columns":10,
"image":"..\/..
at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:330)
at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:61)
at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:81)
... 6 more
Here the map .tmx :
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="20" height="20" tilewidth="12" tileheight="12" infinite="0" nextlayerid="2" nextobjectid="1">
<editorsettings>
<export target="../../android/assets/MyMap.tmx" format="tmx"/>
</editorsettings>
<tileset firstgid="1" source="../mapassets.json"/>
<layer id="1" name="Tile Layer 1" width="20" height="20">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,2,3,4,5,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,21,22,23,24,25,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,31,32,33,34,35,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,41,42,43,44,45,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
</map>
Here is my frustrating mapassets.json(this file is inside assets/mapAssets folder in my project):
{ "columns":10,
"image":"..\/..\/assets\/mapAssets\/mapassets.png",
"imageheight":128,
"imagewidth":128,
"margin":0,
"name":"mapassets",
"spacing":0,
"tilecount":100,
"tiledversion":"1.4.3",
"tileheight":12,
"tilewidth":12,
"type":"tileset",
"version":1.4
}
and here how I load .tmx file:
@Override
public void create () {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera();
camera.setToOrtho(false,w,h);
camera.update();
tiledMap = new TmxMapLoader().load("MyMap.tmx");
tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
Gdx.input.setInputProcessor(this);
}
Upvotes: 1
Views: 279
Reputation: 1148
You get the error because you've saved your tileset as a .json
file but the libGDX implementation in TmxMapLoader
assumes it's in XML.
You can see that in the source code for TmxMapLoader
.
Save your tileset as a .tsx
file instead and reference that from your .tmx
file and it should work.
Upvotes: 1