tarr11 Posted March 10, 2014 Share Posted March 10, 2014 Hi, I'm creating tilemaps using Tiled (0.9.1), and am finding it quite difficult to figure out what GID a tile is, without looking at the JSON code. Is there some easy way to do this? Also, according to this issue in Tiled, it seems like using GIDs is discouraged in Tiled? https://github.com/bjorn/tiled/issues/15 Thanks,Doug Link to comment Share on other sites More sharing options...
Heppell08 Posted March 10, 2014 Share Posted March 10, 2014 I filed on issue on github as this it a TILED issue. I'm also using a JSON as a means for I.D's too.This is TILED issue, not phaser unfortunately. Link to comment Share on other sites More sharing options...
nkholski Posted October 5, 2014 Share Posted October 5, 2014 I know this is an old post, but I got tired of calculating the GID and want to share my solution:function tilePropertyToGid(value, map, property) { var keys, i, i2; if (typeof (property) === "undefined") { property = "type"; } for (i = 0; i < map.tilesets.length; i++) { if (!(map.tilesets[i].hasOwnProperty("tileProperties"))) { continue; } keys = Object.keys(map.tilesets[i].tileProperties); for (i2 = 0; i2 < keys.length; i2++) { if ((map.tilesets[i].tileProperties[keys[i2]].hasOwnProperty(property)) && (map.tilesets[i].tileProperties[keys[i2]][property] === value)) { return (parseInt(keys[i2], 10) + parseInt(map.tilesets[i].firstgid, 10)); } } } console.log("Error: No GID found!"); return false;} The function searches all tiles for a property matching a value/key and return the GID for that tile. Parameters is value for value to search for, map which is a tiled map and property that is the name of the property (default is "type"). You can add properties to tiles in Tiled by right-click a tile in the tile set-view and select "Tile properties". A good thing with this approach is that nothing will break if the GID would change for some reason. kctang and Tilde 2 Link to comment Share on other sites More sharing options...
Recommended Posts