From 184cfd197904a75e15c419c6e8be72f1462d194e Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 11:59:25 -0600 Subject: [PATCH] When creating a Tilemap layer, use Tiled layer offset if no xy specified --- v3/src/gameobjects/tilemap/Tilemap.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index 6c876ac6a..1dc98da68 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -212,7 +212,7 @@ var Tilemap = new Class({ return sprites; }, - // Creates & selects + // Creates & selects, uses layer offset if x,y undefined createStaticLayer: function (layerID, tileset, x, y) { var index = this.getLayerIndex(layerID); @@ -232,12 +232,16 @@ var Tilemap = new Class({ this.currentLayerIndex = index; + // Default the x/y position to match Tiled layer offset, if it exists. + if (x === undefined && this.layers[index].x) { x = this.layers[index].x; } + if (y === undefined && this.layers[index].y) { y = this.layers[index].y; } + var layer = new StaticTilemapLayer(this.scene, this, index, tileset, x, y); this.scene.sys.displayList.add(layer); return layer; }, - // Creates & selects + // Creates & selects, uses layer offset if x,y undefined createDynamicLayer: function (layerID, tileset, x, y) { var index = this.getLayerIndex(layerID); @@ -257,6 +261,10 @@ var Tilemap = new Class({ this.currentLayerIndex = index; + // Default the x/y position to match Tiled layer offset, if it exists. + if (x === undefined && this.layers[index].x) { x = this.layers[index].x; } + if (y === undefined && this.layers[index].y) { y = this.layers[index].y; } + var layer = new DynamicTilemapLayer(this.scene, this, index, tileset, x, y); this.scene.sys.displayList.add(layer); return layer;