Skip to content

Commit b3a74a6

Browse files
committed
ParseTilesets will now correctly handle non-consequtive tile IDs. It also now correctly sets the maxId property, fixing a bug where tiles wouldn't render if from IDs outside the expected range. Fix phaserjs#4367
1 parent e526af7 commit b3a74a6

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

src/tilemaps/parsers/tiled/ParseTilesets.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var ParseTilesets = function (json)
3232

3333
if (set.source)
3434
{
35-
console.warn('Phaser can\'t load external tilesets. Use the Embed Tileset button and then export the map again.');
35+
console.warn('External tilesets unsupported. Use Embed Tileset and re-export');
3636
}
3737
else if (set.image)
3838
{
@@ -71,9 +71,10 @@ var ParseTilesets = function (json)
7171

7272
if (tile.objectgroup.objects)
7373
{
74-
var parsedObjects2 = tile.objectgroup.objects.map(
75-
function (obj) { return ParseObject(obj); }
76-
);
74+
var parsedObjects2 = tile.objectgroup.objects.map(function (obj)
75+
{
76+
return ParseObject(obj);
77+
});
7778

7879
tiles[tile.id].objectgroup.objects = parsedObjects2;
7980
}
@@ -116,11 +117,14 @@ var ParseTilesets = function (json)
116117
for (stringID in newSet.tileData)
117118
{
118119
var objectGroup = newSet.tileData[stringID].objectgroup;
120+
119121
if (objectGroup && objectGroup.objects)
120122
{
121-
var parsedObjects1 = objectGroup.objects.map(
122-
function (obj) { return ParseObject(obj); }
123-
);
123+
var parsedObjects1 = objectGroup.objects.map(function (obj)
124+
{
125+
return ParseObject(obj);
126+
});
127+
124128
newSet.tileData[stringID].objectgroup.objects = parsedObjects1;
125129
}
126130
}
@@ -135,16 +139,24 @@ var ParseTilesets = function (json)
135139
}
136140
else
137141
{
138-
var newCollection = new ImageCollection(set.name, set.firstgid, set.tilewidth,
139-
set.tileheight, set.margin, set.spacing, set.properties);
142+
var newCollection = new ImageCollection(set.name, set.firstgid, set.tilewidth, set.tileheight, set.margin, set.spacing, set.properties);
140143

141-
for (stringID in set.tiles)
144+
var maxId = 0;
145+
146+
for (t = 0; t < set.tiles.length; t++)
142147
{
143-
var image = set.tiles[stringID].image;
144-
var gid = set.firstgid + parseInt(stringID, 10);
148+
tile = set.tiles[t];
149+
150+
var image = tile.image;
151+
var tileId = parseInt(tile.id, 10);
152+
var gid = set.firstgid + tileId;
145153
newCollection.addImage(gid, image);
154+
155+
maxId = Math.max(tileId, maxId);
146156
}
147157

158+
newCollection.maxId = maxId;
159+
148160
imageCollections.push(newCollection);
149161
}
150162

0 commit comments

Comments
 (0)