TIlemap & layers: GetTileAtWorldXY

This commit is contained in:
Michael Hadley 2017-11-16 13:27:52 -06:00
parent c2268f3dee
commit e6c6d1ddce
6 changed files with 35 additions and 0 deletions

View file

@ -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);

View 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;

View file

@ -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'),

View file

@ -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);

View file

@ -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,

View file

@ -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);