mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
TIlemap & layers: GetTileAtWorldXY
This commit is contained in:
parent
c2268f3dee
commit
e6c6d1ddce
6 changed files with 35 additions and 0 deletions
|
@ -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);
|
||||
|
|
15
v3/src/gameobjects/tilemap/components/GetTileAtWorldXY.js
Normal file
15
v3/src/gameobjects/tilemap/components/GetTileAtWorldXY.js
Normal file
|
@ -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;
|
|
@ -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'),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue