1

I started about a week ago with libGDX and I have a problem loading in a tmx. Tiled Map. As far as I see the game doesn't find the "test.tmx", but I don't know why! The path is correct as far as I can see.

I use "Tiled" as the Map Editor. The Layer Format is Base64.

This Screenshot showing the Code I use to load in the tmx. file and the Project Structure: http://abload.de/img/tmxgpptc.png

I get the following error Message:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error parsing file: res/map/test.tmx
at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:83)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:113)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:101)
at de.knightsquest.states.Play.<init>(Play.java:59)
at de.knightsquest.handler.GameStateManager.getState(GameStateManager.java:35)
at de.knightsquest.handler.GameStateManager.pushState(GameStateManager.java:46)
at de.knightsquest.handler.GameStateManager.<init>(GameStateManager.java:20)
at de.knightsquest.game.Game.create(Game.java:38)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: res\map\test.tmx (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.reader(FileHandle.java:164)
at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:81)
... 9 more
The_Blog
  • 155
  • 1
  • 12

2 Answers2

2

You should read this wiki article about file handling.

You have to place the res\map\test.tmx inside your android project in the assets folder. The way you load the map assumes an internal (android/assets) file path.

Furthermore I'd advise you to load the TiledMap via an AssetManager.

noone
  • 19,520
  • 5
  • 61
  • 76
1

Presuming you followed the tutorial of ForeignGuyMike, you will have one project, but in general you auto-generate your projects with the LibGDX-Tool. When loading ressources LibGDX looks up in the assets folder of the android project. Instead of using the res-folder from before, use the assets-folder. If you auto-generated the project the dependencies are all correctly established and by calling the load method, libgdx looks up the file in the assets-folder in your android project. Thing is your filepath should now only be "maps/test.tmx" since it's already looking in the assets folder.

In general it's the same idea as the answer above I guess... I just disliked the idea of moving the whole folder structure, because assets are our ressources...

Craid
  • 11
  • 2