title: Where do the Tile IDs come from in Tiled?
body: <p>I've used <a href="http://doc.mapeditor.org/" rel="nofollow">Tiled</a> to build JSON tilemap files for <a href="http://phaser.io/" rel="nofollow">Phaser</a> games in the past. I would now like to build my <a href="http://phaser.io/examples/v2/loader/load-tilemap-json" rel="nofollow">JSON map files</a> on the fly with PHP. </p>
  
  <p>Here's an example object:</p>
  
  <pre><code>{
      "height": 50,
      "layers": [{
          "data": [5884, 5885, 5886, 5887, 5888, 5885],
          "height": 50,
          "name": "background",
          "opacity": 1,
          "type": "tilelayer",
          "visible": true,
          "width": 50,
          "x": 0,
          "y": 0
      }],
      "orientation": "orthogonal",
      "properties": {},
      "tileheight": 16,
      "tilesets": [{
          "firstgid": 1,
          "image": "tiles.png",
          "imageheight": 1684,
          "imagewidth": 2738,
          "margin": 1,
          "name": "tiles",
          "properties": {},
          "spacing": 1,
          "tileheight": 16,
          "tilewidth": 16
      }],
      "tilewidth": 16,
      "version": 1,
      "width": 50
  }
  </code></pre>
  
  <p>The properties are pretty self-explanatory and are documented on <a href="https://github.com/bjorn/tiled/wiki/JSON-Map-Format" rel="nofollow">Github</a>, which references the <a href="http://doc.mapeditor.org/reference/tmx-map-format/" rel="nofollow">TMX Map format docs</a> on the Tiled website, but neither explain how the tile id's for the layer's <code>data</code> property are generated.</p>
  
  <p>Two questions:</p>
  
  <p>1) How are the Tile Ids generated for the "data" array? For example, If I have a 5x5 tile sheet, would they just be 1 thru 25 left to right, top to bottom?</p>
  
  <p>2) The data array uses global ids, which are unique across all the tile sheets. How are these generated? For example, if I have 3 5x5 tile sheets, would they be 1-75? But in what order?</p>