TileSet.getTileData() has been updated so it will return tile data from either Tiled 1.1.x or the new Tiled 1.2.x JSON structure. Fix #3998

This commit is contained in:
Richard Davey 2018-09-25 16:20:34 +01:00
parent 2d9477680b
commit 2985a97c56
2 changed files with 21 additions and 1 deletions

View file

@ -7,6 +7,7 @@
### Updates
* The Loader has been updated to handle the impact of you destroying the game instance while still processing files. It will no longer throw cache and texture related errors. Fix #4049 (thanks @pantoninho)
* `TileSet.getTileData()` has been updated so it will return tile data from either Tiled 1.1.x or the new Tiled 1.2.x JSON structure. Fix #3998 (thanks @martin-pabst @halgorithm)
### Bug Fixes

View file

@ -178,6 +178,15 @@ var Tileset = new Class({
* @since 3.0.0
*/
this.texCoordinates = [];
/**
* A look-up map that converts between Tiled 1.1 and Tiled 1.2 tile data.
*
* @name Phaser.Tilemaps.Tileset#tileIndexMap
* @type {object}
* @since 3.14.0
*/
this.tileIndexMap = null;
},
/**
@ -214,7 +223,17 @@ var Tileset = new Class({
{
if (!this.containsTileIndex(tileIndex)) { return null; }
return this.tileData[tileIndex - this.firstgid];
if (!this.tileIndexMap)
{
this.tileIndexMap = {};
for (var i = 0; i < this.tileData.length; i++)
{
this.tileIndexMap[this.tileData[i]['id']] = this.tileData[i];
}
}
return this.tileIndexMap[tileIndex - this.firstgid];
},
/**