Jump to content

export tilemap as json


kl76947
 Share

Recommended Posts

  • 1 year later...

Is there a real answer to this question? What is the best way to save/export a Phaser.TileMap as JSON to be reloaded/reinstantiated later?

As of 2.4.6 - Baerlon, the public methods do not appear to contain built-in functionality for this.

Phaser's accepted tile map formats (Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON) aren't particularly well documented themselves. I assume that the latter is "the Tiled JSON format" (based on the TMX format), but I have not figured out what the CSV format actually is. Looking at the examples (e.g. catastrophi_level1.csv), "CSV" looks to be nothing more than a map of tile integer IDs - no objects, collision data, layers, etc. That pretty much necessitates any *useful* Phaser TileMap save/export to result in the TILED_JSON format.

Link to comment
Share on other sites

I've gotten this far:

tileMapLayer_to_CSV = function (layer) {
  var csv = '';
  for (var y = 0; y < layer.data.length; y++) {
    if (y > 0) {
      csv += '\n';
    }
    for (var x = 0; x < layer.data[y].length; x++) {
      if (x > 0) {
        csv += ',';
      }
      csv += layer.data[y][x].index;
    }
  }
  return csv;
}; // end tileMapLayer_to_CSV()

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...