Skip to content

Commit 2985a97

Browse files
committed
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 phaserjs#3998
1 parent 2d94776 commit 2985a97

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Updates
88

99
* 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)
10+
* `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)
1011

1112
### Bug Fixes
1213

src/tilemaps/Tileset.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ var Tileset = new Class({
178178
* @since 3.0.0
179179
*/
180180
this.texCoordinates = [];
181+
182+
/**
183+
* A look-up map that converts between Tiled 1.1 and Tiled 1.2 tile data.
184+
*
185+
* @name Phaser.Tilemaps.Tileset#tileIndexMap
186+
* @type {object}
187+
* @since 3.14.0
188+
*/
189+
this.tileIndexMap = null;
181190
},
182191

183192
/**
@@ -214,7 +223,17 @@ var Tileset = new Class({
214223
{
215224
if (!this.containsTileIndex(tileIndex)) { return null; }
216225

217-
return this.tileData[tileIndex - this.firstgid];
226+
if (!this.tileIndexMap)
227+
{
228+
this.tileIndexMap = {};
229+
230+
for (var i = 0; i < this.tileData.length; i++)
231+
{
232+
this.tileIndexMap[this.tileData[i]['id']] = this.tileData[i];
233+
}
234+
}
235+
236+
return this.tileIndexMap[tileIndex - this.firstgid];
218237
},
219238

220239
/**

0 commit comments

Comments
 (0)