1

At the moment I have two different ways of loading tilemaps, one is by reading in a .tmx file exported from Tiled with the native libGDX class TmxMapLoader like so:

tiledMap = new TmxMapLoader().load("tilemap/moontilemap.tmx");

And another way is by creating a 2D array and putting in tile IDs in there, then saving that to a JSON file, like this:

public static void saveMap(String id, String name, int[][][] map) {

    CustomMapData mapData = new CustomMapData();
    mapData.id = id;
    mapData.name = name;
    mapData.map = map;

    Gdx.files.local("maps/").file().mkdirs();
    FileHandle file = Gdx.files.local("maps/" + id + ".map");
    file.writeString(json.prettyPrint(mapData), false);

}

Ideally I'd like to combine these, but I'm not sure how to. I want to continue using Tiled to create my initial tilemaps and save them in .tmx files, but I want the player to edit the maps and then alter the data in the .tmx file to save these changes. How do I go about this?

werner_b
  • 47
  • 2
  • 11
  • I'm personally also using Tiled editor for generating maps, but I'm exporting maps (and tile sets) to json and I'm parsing those json files manually (json files are easy to manipulate). Maybe you can do the same? – MilanG May 16 '19 at 11:29
  • @MilanG interesting, could you elaborate on how you export it to JSON? I don't know a whole lot about reading and writing files so that's probably a pretty basic question – werner_b May 17 '19 at 12:03
  • Just check Tiled menus. There is an option to export in different file formats. – MilanG May 17 '19 at 12:06

0 Answers0