mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 13:43:26 +00:00
Tilemap & layer WorldXY methods: get, has, put, remove
This commit is contained in:
parent
ea989edca1
commit
3266974ea0
8 changed files with 94 additions and 13 deletions
|
@ -292,11 +292,11 @@ var Tilemap = new Class({
|
|||
return TilemapComponents.GetTileAt(tileX, tileY, nonNull, layer);
|
||||
},
|
||||
|
||||
getTileAtWorldXY: function (worldX, worldY, nonNull, layer)
|
||||
getTileAtWorldXY: function (worldX, worldY, nonNull, camera, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
if (layer === null) { return null; }
|
||||
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, layer);
|
||||
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, layer);
|
||||
},
|
||||
|
||||
getTilesWithin: function (tileX, tileY, width, height, layer)
|
||||
|
@ -318,6 +318,13 @@ var Tilemap = new Class({
|
|||
return TilemapComponents.HasTileAt(tileX, tileY, layer);
|
||||
},
|
||||
|
||||
hasTileAtWorldXY: function (worldX, worldY, camera, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
if (layer === null) { return null; }
|
||||
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, layer);
|
||||
},
|
||||
|
||||
layer: {
|
||||
get: function ()
|
||||
{
|
||||
|
@ -338,6 +345,14 @@ var Tilemap = new Class({
|
|||
return TilemapComponents.PutTile(tile, tileX, tileY, layer);
|
||||
},
|
||||
|
||||
putTileWorldXY: function (tile, worldX, worldY, camera, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
if (this._isStaticCall(layer, 'putTileWorldXY')) { return null; }
|
||||
if (layer === null) { return null; }
|
||||
return TilemapComponents.PutTileWorldXY(tile, worldX, worldY, camera, layer);
|
||||
},
|
||||
|
||||
randomize: function (tileX, tileY, width, height, indices, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
|
@ -364,6 +379,14 @@ var Tilemap = new Class({
|
|||
return TilemapComponents.RemoveTile(tileX, tileY, replaceWithNull, layer);
|
||||
},
|
||||
|
||||
removeTileWorldXY: function (worldX, worldY, replaceWithNull, camera, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
if (this._isStaticCall(layer, 'removeTileWorldXY')) { return null; }
|
||||
if (layer === null) { return null; }
|
||||
return TilemapComponents.RemoveTileWorldXY(worldX, worldY, replaceWithNull, camera, layer);
|
||||
},
|
||||
|
||||
replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
var GetTileAt = require('./GetTileAt');
|
||||
var SnapFloor = require('../../../math/snap/SnapFloor');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
|
||||
// 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 GetTileAtWorldXY = function (worldX, worldY, nonNull, camera, layer)
|
||||
{
|
||||
var tileX = SnapFloor(worldX, layer.tileWidth) / layer.tileWidth;
|
||||
var tileY = SnapFloor(worldY, layer.tileHeight) / layer.tileHeight;
|
||||
var tileX = WorldToTileX(worldX, camera, layer);
|
||||
var tileY = WorldToTileY(worldY, camera, layer);
|
||||
|
||||
return GetTileAt(tileX, tileY, nonNull, layer);
|
||||
};
|
||||
|
|
13
v3/src/gameobjects/tilemap/components/HasTileAtWorldXY.js
Normal file
13
v3/src/gameobjects/tilemap/components/HasTileAtWorldXY.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
var HasTileAt = require('./HasTileAt');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
|
||||
var HasTileAtWorldXY = function (worldX, worldY, camera, layer)
|
||||
{
|
||||
var tileX = WorldToTileX(worldX, camera, layer);
|
||||
var tileY = WorldToTileY(worldY, camera, layer);
|
||||
|
||||
return HasTileAt(tileX, tileY, layer);
|
||||
};
|
||||
|
||||
module.exports = HasTileAtWorldXY;
|
12
v3/src/gameobjects/tilemap/components/PutTileWorldXY.js
Normal file
12
v3/src/gameobjects/tilemap/components/PutTileWorldXY.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
var PutTile = require('./PutTile');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
|
||||
var PutTileWorldXY = function (tile, worldX, worldY, camera, layer)
|
||||
{
|
||||
var tileX = WorldToTileX(worldX, camera, layer);
|
||||
var tileY = WorldToTileY(worldY, camera, layer);
|
||||
return PutTile(tile, tileX, tileY, layer);
|
||||
};
|
||||
|
||||
module.exports = PutTileWorldXY;
|
12
v3/src/gameobjects/tilemap/components/RemoveTileWorldXY.js
Normal file
12
v3/src/gameobjects/tilemap/components/RemoveTileWorldXY.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
var RemoveTile = require('./RemoveTile');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
|
||||
var RemoveTileWorldXY = function (worldX, worldY, replaceWithNull, camera, layer)
|
||||
{
|
||||
var tileX = WorldToTileX(worldX, camera, layer);
|
||||
var tileY = WorldToTileY(worldY, camera, layer);
|
||||
return RemoveTile(tileX, tileY, replaceWithNull, layer);
|
||||
};
|
||||
|
||||
module.exports = RemoveTileWorldXY;
|
|
@ -8,10 +8,13 @@ module.exports = {
|
|||
GetTileAtWorldXY: require('./GetTileAtWorldXY'),
|
||||
GetTilesWithin: require('./GetTilesWithin'),
|
||||
HasTileAt: require('./HasTileAt'),
|
||||
HasTileAtWorldXY: require('./HasTileAtWorldXY'),
|
||||
IsInLayerBounds: require('./IsInLayerBounds'),
|
||||
PutTile: require('./PutTile'),
|
||||
PutTileWorldXY: require('./PutTileWorldXY'),
|
||||
Randomize: require('./Randomize'),
|
||||
RemoveTile: require('./RemoveTile'),
|
||||
RemoveTileWorldXY: require('./RemoveTileWorldXY'),
|
||||
ReplaceByIndex: require('./ReplaceByIndex'),
|
||||
Shuffle: require('./Shuffle'),
|
||||
SwapByIndex: require('./SwapByIndex'),
|
||||
|
|
|
@ -137,9 +137,9 @@ var DynamicTilemapLayer = new Class({
|
|||
return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer);
|
||||
},
|
||||
|
||||
getTileAtWorldXY: function (worldX, worldY, nonNull)
|
||||
getTileAtWorldXY: function (worldX, worldY, nonNull, camera)
|
||||
{
|
||||
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, this.layer);
|
||||
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, this.layer);
|
||||
},
|
||||
|
||||
getTilesWithin: function (tileX, tileY, width, height)
|
||||
|
@ -152,11 +152,21 @@ var DynamicTilemapLayer = new Class({
|
|||
return TilemapComponents.HasTileAt(tileX, tileY, this.layer);
|
||||
},
|
||||
|
||||
hasTileAtWorldXY: function (worldX, worldY, camera)
|
||||
{
|
||||
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer);
|
||||
},
|
||||
|
||||
putTile: function (tile, tileX, tileY)
|
||||
{
|
||||
return TilemapComponents.PutTile(tile, tileX, tileY, this.layer);
|
||||
},
|
||||
|
||||
putTileWorldXY: function (tile, worldX, worldY, camera)
|
||||
{
|
||||
return TilemapComponents.PutTileWorldXY(tile, worldX, worldY, camera, this.layer);
|
||||
},
|
||||
|
||||
randomize: function (tileX, tileY, width, height, indices)
|
||||
{
|
||||
TilemapComponents.Randomize(tileX, tileY, width, height, indices, this.layer);
|
||||
|
@ -168,6 +178,11 @@ var DynamicTilemapLayer = new Class({
|
|||
return TilemapComponents.RemoveTile(tileX, tileY, replaceWithNull, this.layer);
|
||||
},
|
||||
|
||||
removeTileWorldXY: function (worldX, worldY, replaceWithNull, camera)
|
||||
{
|
||||
return TilemapComponents.RemoveTileWorldXY(worldX, worldY, replaceWithNull, camera, this.layer);
|
||||
},
|
||||
|
||||
replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height)
|
||||
{
|
||||
TilemapComponents.ReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, this.layer);
|
||||
|
|
|
@ -298,9 +298,9 @@ var StaticTilemapLayer = new Class({
|
|||
return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer);
|
||||
},
|
||||
|
||||
getTileAtWorldXY: function (worldX, worldY, nonNull)
|
||||
getTileAtWorldXY: function (worldX, worldY, nonNull, camera)
|
||||
{
|
||||
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, this.layer);
|
||||
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, this.layer);
|
||||
},
|
||||
|
||||
getTilesWithin: function (tileX, tileY, width, height)
|
||||
|
@ -313,6 +313,11 @@ var StaticTilemapLayer = new Class({
|
|||
return TilemapComponents.HasTileAt(tileX, tileY, this.layer);
|
||||
},
|
||||
|
||||
hasTileAtWorldXY: function (worldX, worldY, camera)
|
||||
{
|
||||
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer);
|
||||
},
|
||||
|
||||
worldToTileX: function (worldX, camera)
|
||||
{
|
||||
return TilemapComponents.WorldToTileX(worldX, camera, this.layer);
|
||||
|
|
Loading…
Reference in a new issue