Skip to content

Commit ab29015

Browse files
committed
Convenience tile getters for looking up tileset & tilemap layer
1 parent c63400a commit ab29015

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

src/gameobjects/tilemap/Tile.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,35 @@ var Tile = new Class({
510510
{
511511
return this.pixelY + this.height / 2;
512512
}
513-
}
513+
},
514514

515+
/**
516+
* The tileset that contains this Tile. This will only return null if accessed from a LayerData
517+
* instance before the tile is placed within a StaticTilemapLayer or DynamicTilemapLayer.
518+
* @property {Tileset|null} tileset
519+
* @readonly
520+
*/
521+
tileset: {
522+
get: function ()
523+
{
524+
var tilemapLayer = this.tilemapLayer;
525+
return tilemapLayer ? tilemapLayer.tileset : null;
526+
}
527+
},
528+
529+
/**
530+
* The tilemap layer that contains this Tile. This will only return null if accessed from a
531+
* LayerData instance before the tile is placed within a StaticTilemapLayer or
532+
* DynamicTilemapLayer.
533+
* @property {StaticTilemapLayer|DynamicTilemapLayer|null} tilemapLayer
534+
* @readonly
535+
*/
536+
tilemapLayer: {
537+
get: function ()
538+
{
539+
return this.layer.tilemapLayer;
540+
}
541+
}
515542
});
516543

517544
module.exports = Tile;

0 commit comments

Comments
 (0)