Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGDX having trouble with tiled maps  (Read 2462 times)
0 Members and 1 Guest are viewing this topic.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Posted 2013-10-29 20:48:30 »

So I've recently began to learn how to use LibGDX and I'm now trying to load a tiled map. I've been reading this.

So I have my TMX file located at assets/maps/tilemapxml.tmx along with the .png and .pack files. I'm trying to load it via the AssetManager, using this code:

1  
2  
3  
4  
5  
6  
7  
AssetManager manager = new AssetManager();
manager.setLoader(TiledMap.class, new TmxMapLoader(
      new InternalFileHandleResolver()));
manager.load(mapFile, TiledMap.class);
manager.finishLoading();

map = manager.get(mapFile);


Then I'm trying to render the map how it says to:

1  
new OrthogonalTiledMapRenderer(map, unitScale);


But I get a lot of errors like so;

1  
2  
Couldn't load dependencies of asset: maps/tilemapxml.tmx
Error parsing file: maps/tilemapxml.tmx



Q1: Am I doing anything wrong at the moment??
Q2: I'm confused and I feel like I'm missing a lot of code here. What else do I need to do?

Why are all OpenGL tutorials written in Brainf**k?
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 133
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2013-10-29 22:49:32 »

iirc the system of tiled maps that uses .pack is deprecated for libgdx. Try updating libgdx using the setup-ui or downloading the latest nightly, and check out the new maps api here.

But that's not why you're getting an error - the old system should still work, it's just harder to use, more tedious, and not supported. The error probably means you misplaced the .png, so even if it's in the same folder try opening up the .tmx in notepad or notepad++ and see what the path of the .png is supposed to be (oh and try refreshing the project first before you do anything else).
Offline nexsoftware

Junior Member


Medals: 9



« Reply #2 - Posted 2013-10-30 04:41:04 »

LibGDX does not support storing your map layer data in XML format. Use csv, base64, base64-gzip, or base64-zlib to store your map layer data. This is probably the cause of the errors.

Using the tiled-preprocessor is still supported with the new api, but you have to use AtlasTmxMapLoader to load the map (and use the latest version of the tiled-preprocessor).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 133
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2013-10-30 04:56:19 »

LibGDX does not support storing your map layer data in XML format. Use csv, base64, base64-gzip, or base64-zlib to store your map layer data. This is probably the cause of the errors.
He named it tilemapxml. It's still a .tmx though.
Offline nexsoftware

Junior Member


Medals: 9



« Reply #4 - Posted 2013-10-30 05:32:36 »

He named it tilemapxml. It's still a .tmx though.

And one of the formats for tmx files is to store layer data as xml, which is not supported. I made the educated guess that if the file was named tilemapxml.tmx that it used the xml data format.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #5 - Posted 2013-10-30 12:53:59 »

I decided to take a different approach and load it with TmxMapLoader. I followed this tutorial. However I still get a lot of errors parsing the file. I was previously using XML encoding, so I changed it to base64 and also tried base64 with gzip compression, however I still get a lot of errors. Here's the stack trace:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error parsing file: maps/tilemap.tmx
   at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:79)
   at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:116)
   at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:104)
   at en.mash.splooke.maps.Map.loadMap(Map.java:19)
   at en.mash.splooke.screen.GameScreen.show(GameScreen.java:40)
   at com.badlogic.gdx.Game.setScreen(Game.java:62)
   at en.mash.splooke.screen.SplashScreen.render(SplashScreen.java:28)
   at com.badlogic.gdx.Game.render(Game.java:46)
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:207)
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: com.badlogic.gdx.utils.SerializationException: Error parsing XML on line 1 near: <?xml version="1.0" encoding=
   at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:322)
   at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:60)
   at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:67)
   at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:77)
   ... 9 more


Also here is my TMX file:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
<?xml version="1.0" encoding="utf-8"?>
<map version="1.0" orientation="orthogonal" width="200" height="32" tilewidth="32" tileheight="32">
  <tileset firstgid="1" name="Blocks" tilewidth="32" tileheight="32" spacing="0" margin="0">
    <image source="tiles.png" />
  </tileset>
  <layer name="Platforms" width="200" height="32">
    <properties>
      <property name="@Description" value="" />
    </properties>
    <data encoding="base64">this is mainly just A's, I removed it because it's so long</data>
  </layer>
</map>


This is how I'm loading the map file:
1  
2  
3  
4  
5  
6  
7  
8  
   public Map(String file) {
      this.mapFile = file;
   }

   public void loadMap(float unitScale) {
      map = new TmxMapLoader().load(mapFile);
      renderer = new OrthogonalTiledMapRenderer(map, unitScale);
   }


I checked the tutorial twice over and my code should work.  Huh

Why are all OpenGL tutorials written in Brainf**k?
Offline nexsoftware

Junior Member


Medals: 9



« Reply #6 - Posted 2013-10-30 13:07:00 »

That BOM () at the beginning of your file is the problem. Try resaving the file without the BOM. Tiled doesn't usually add that, did you edit the file with something else afterward? You should be able to open it in something like Notepadd++ and just save without the BOM.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #7 - Posted 2013-10-30 13:26:57 »

That BOM () at the beginning of your file is the problem. Try resaving the file without the BOM. Tiled doesn't usually add that, did you edit the file with something else afterward? You should be able to open it in something like Notepadd++ and just save without the BOM.

Thank you. I was using Tide map editor which must have added it. I opened it in notepad previously but didn't see the BOM but using the eclipse text editor let me remove it.

Why are all OpenGL tutorials written in Brainf**k?
Offline ignatius3

Junior Newbie





« Reply #8 - Posted 2014-02-13 15:13:40 »

Hello,

I'm having the same problem, I'm using Tiled and I've tried with every possible format (except xml). And also creating new maps but I keep getting the same error while parsing whatever I do:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error parsing file: /maps/tres.tmx
   at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:79)
   at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:116)
   at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:104)
   at com.cipolino.drinkgame.Screens.GameScreen.show(GameScreen.java:43)
   at com.badlogic.gdx.Game.setScreen(Game.java:62)
   at com.cipolino.drinkgame.DrinkingGame.create(DrinkingGame.java:13)
   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: \maps\tres.tmx (Internal)
   at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:133)
   at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:76)


This is where I load the map:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
@Override
   public void show() {
      //Cargamos mapa
     TmxMapLoader loader = new TmxMapLoader();
      map = loader.load("/maps/Jar.tmx");
     
      //pasamos mapa al renderer
     render = new OrthogonalTiledMapRenderer(map);

   }


And this the Tmx File (Jar.tmx):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="18" height="24" tilewidth="64" tileheight="64">
 <tileset firstgid="1" name="tilesv1" tilewidth="64" tileheight="64" spacing="1" margin="1">
  <tileoffset x="1" y="1"/>
  <image source="tilesv.png" width="196" height="196"/>
 </tileset>
 <layer name="Tile Layer 1" width="18" height="24">
  <data encoding="base64" compression="zlib">
   eJxjZWBgYKUSZgdiRiIxBx5zGEmwE5/a4WAOM5awIjaMGdHsRLefXH+NmjNqzqg5g9McTgZEvmejwBxi7cCHmahkHz4MABxUBzE=
  </data>
 </layer>
</map>


Obviously I have the file tilesv.png in the package assets.

Any Ideas of what could be wrong?
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #9 - Posted 2014-02-13 15:22:03 »

This is a really old thread.  Roll Eyes

Anyway, if you'd have read the previously replies, the problem is that a BOM has been saved in the file. Open the file with a text editor such as eclipse text editor or notepad++ and you should be able to remove the BOM.

Why are all OpenGL tutorials written in Brainf**k?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ignatius3

Junior Newbie





« Reply #10 - Posted 2014-02-13 15:42:51 »

Yes, sorry for re-opening the thread, it was exactly the same question so I thought it was the right thing to do.

Thank you for the answer but the code for the Tmx I posted was from Eclipse Text Editor and I've also opened it with Notepad++. I even tried with File BOM detector but there is no BOM. That's why I was asking for other ideas.

Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #11 - Posted 2014-02-13 15:50:24 »

That's odd. There's obviously an error parsing the file. Have you edited it? All I can suggest is trying to recreate the map.

Why are all OpenGL tutorials written in Brainf**k?
Offline ignatius3

Junior Newbie





« Reply #12 - Posted 2014-02-13 15:58:48 »

Oh! just found it... it couldn't find the file because I put "/" in front of maps in the path to the file...

Thank you for your help Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (39 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!