Skip to content

Commit afb094a

Browse files
committed
Merge pull request #1126 from beeglebug/feature/tile-properties
copy tile properties to tiles when parsing map
2 parents cc1c794 + 23f077a commit afb094a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/tilemap/TilemapParser.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,41 @@ Phaser.TilemapParser = {
491491

492492
}
493493

494+
// assign tile properties
495+
496+
var i,j,k;
497+
var layer, tile, sid, set;
498+
499+
// go through each of the map layers
500+
for (i = 0; i < map.layers.length; i++)
501+
{
502+
layer = map.layers[i];
503+
504+
// rows of tiles
505+
for (j = 0; j < layer.data.length; j++)
506+
{
507+
row = layer.data[j];
508+
509+
// individual tiles
510+
for (k = 0; k < row.length; k++)
511+
{
512+
tile = row[k];
513+
514+
if(tile.index < 0) { continue; }
515+
516+
// find the relevant tileset
517+
sid = map.tiles[tile.index][2];
518+
set = map.tilesets[sid];
519+
520+
// if that tile type has any properties, add them to the tile object
521+
if(set.tileProperties && set.tileProperties[tile.index - set.firstgid]) {
522+
tile.properties = set.tileProperties[tile.index - set.firstgid];
523+
}
524+
}
525+
}
526+
}
527+
528+
494529
return map;
495530

496531
}

0 commit comments

Comments
 (0)