3

I currenly load my tiled map from assets folder.

TiledMap tileMap = new TmxMapLoader().load("assets/level1.tmx");

But I want to make something like level of the day. Is it possible to load a tiled map from a string?

A string would be the content of a .tmx file.

Example http://pastebin.com/WpV90Hma

Boldijar Paul
  • 5,405
  • 9
  • 46
  • 94

2 Answers2

2

The easiest way would probably be to create a (temporary) FileHandle with the content and use that to load the map.

By default TmxMapLoader will use an InternalFileHandleResolver. This won't work, because you cannot create internal files at runtime.

That's why you would instead use an ExternalFileHandleResolver for the map loader, create an external file and write your map of the day as a string into it.

String mapOfTheDay = ...;
FileHandle mapOfTheDayFile = Gdx.files.external("mygame/mapoftheday.tmx");
mapOfTheDayFile.writeString(mapOfTheDay, false);
TiledMap tileMap = new TmxMapLoader(new ExternalFileHandleResolver()).load("mygame/mapoftheday.tmx");
noone
  • 19,520
  • 5
  • 61
  • 76
0

Inheriting and rewriting methods from TmxLoader, I am able to load a map from a XML String: http://pastebin.com/gQHQv6eV

!! BUT !!, this is very crappy and only loads really basics TMX files. It can be continued to load complex TMX but I dont need it for now.

Files referenced by the TMX (tilesets...) must be in your app working directory.

mr smok
  • 11
  • 3