Reputation: 435
Ive been learning to code games in java and libgdx. My most hated part of any language Ive attempted is the Level Editor (.TMX , tiled) parsing. The Github for libgdx says there is a helpful class made for this which Ive been trying to follow the instructions but Im stuck.
Basically if I comment out the following line of code, the app runs fine but of course without any level elements included. When I have this line in code it crashes my phone instantly whilst loading app:
TiledMap map
public Level(OrthographicCamera camera) {
map = new TmxMapLoader().load("level1.tmx"); /// THIS LINE CRASHES IT
}
I have checked the file 'level1.tmx' definitely exists in my 'assets' folder inside the Android folders of the game hierarchy.
If you do need the rest of my code Im happy to put it up but there is lots of garbage there not related to the problem. Thanks for any help
EDIT: One thing i think it may be is the type of file Im making in Tiled Editor. (ie. I chose zlib compression) other options were XML CSV and i think gzip
Upvotes: 0
Views: 2092
Reputation: 3211
If your error is "unable to load file "....tiles-brown.png" then go to the folder in windows where you've stored the .tmx map. Right click and open in notepad. There you will see a reference path for each asset used on top of the file. Make sure the asset exists in the specified path in your project. If it doesn't or is different change it to where you store the assets for this map. Then save and refresh the android project. This should solve the problem.
Upvotes: 1
Reputation: 19776
You do not have to load the textures yourself. The loader will load all referenced textures for you, but you will have to put them in your assets folder at the same location which was used when creating the map with TilEd. Since you didn't do that right, you get the exception.
A good way to do this is creating a folder levels
and a folder textures
in your assets
directory. Put your .tmx files in levels
and the tilesets in textures
. Now when you import a tileset from TilEd, it will be referenced as ../textures/tileset.png
. To make sure this is correct, you can check the .tmx file. Do not use absolute file paths!
Upvotes: 0