diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index ffe322ced..a34adaad2 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -259,6 +259,13 @@ var Tilemap = new Class({ return TilemapComponents.GetTileAt(tileX, tileY, nonNull, layer); }, + getTileAtWorldXY: function (worldX, worldY, nonNull, layer) + { + layer = this.getLayer(layer); + if (layer === null) { return null; } + return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, layer); + }, + getTilesWithin: function (tileX, tileY, width, height, layer) { layer = this.getLayer(layer); diff --git a/v3/src/gameobjects/tilemap/components/GetTileAtWorldXY.js b/v3/src/gameobjects/tilemap/components/GetTileAtWorldXY.js new file mode 100644 index 000000000..1ca0620c1 --- /dev/null +++ b/v3/src/gameobjects/tilemap/components/GetTileAtWorldXY.js @@ -0,0 +1,15 @@ +var GetTileAt = require('./GetTileAt'); +var SnapFloor = require('../../../math/snap/SnapFloor'); + +// NOTE: phaser v2 version doesn't account for TilemapLayer's XY, so neither does this version +// currently. + +var GetTileAtWorldXY = function (worldX, worldY, nonNull, layer) +{ + var tileX = SnapFloor(worldX, layer.tileWidth) / layer.tileWidth; + var tileY = SnapFloor(worldY, layer.tileHeight) / layer.tileHeight; + + return GetTileAt(tileX, tileY, nonNull, layer); +}; + +module.exports = GetTileAtWorldXY; diff --git a/v3/src/gameobjects/tilemap/components/index.js b/v3/src/gameobjects/tilemap/components/index.js index a4a4378ee..b07b74f7c 100644 --- a/v3/src/gameobjects/tilemap/components/index.js +++ b/v3/src/gameobjects/tilemap/components/index.js @@ -4,6 +4,7 @@ module.exports = { Fill: require('./Fill'), ForEachTile: require('./ForEachTile'), GetTileAt: require('./GetTileAt'), + GetTileAtWorldXY: require('./GetTileAtWorldXY'), GetTilesWithin: require('./GetTilesWithin'), HasTileAt: require('./HasTileAt'), IsInLayerBounds: require('./IsInLayerBounds'), diff --git a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js index 751455d54..fc9c684b3 100644 --- a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js +++ b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js @@ -119,6 +119,11 @@ var DynamicTilemapLayer = new Class({ return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer); }, + getTileAtWorldXY: function (worldX, worldY, nonNull) + { + return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, this.layer); + }, + getTilesWithin: function (tileX, tileY, width, height) { return TilemapComponents.GetTilesWithin(tileX, tileY, width, height, this.layer); diff --git a/v3/src/gameobjects/tilemap/parsers/ParseTiledJSON.js b/v3/src/gameobjects/tilemap/parsers/ParseTiledJSON.js index f57bf736f..b0416b681 100644 --- a/v3/src/gameobjects/tilemap/parsers/ParseTiledJSON.js +++ b/v3/src/gameobjects/tilemap/parsers/ParseTiledJSON.js @@ -76,6 +76,8 @@ var ParseJSONTiled = function (key, json, insertNull) y: curl.y, width: curl.width, height: curl.height, + tileWidth: json.tilewidth, + tileHeight: json.tileheight, widthInPixels: curl.width * json.tilewidth, heightInPixels: curl.height * json.tileheight, alpha: curl.opacity, diff --git a/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js b/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js index 3b4b94b16..fe5e93a77 100644 --- a/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js +++ b/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js @@ -280,6 +280,11 @@ var StaticTilemapLayer = new Class({ return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer); }, + getTileAtWorldXY: function (worldX, worldY, nonNull) + { + return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, this.layer); + }, + getTilesWithin: function (tileX, tileY, width, height) { return TilemapComponents.GetTilesWithin(tileX, tileY, width, height, this.layer);