mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
Tilemap & Layers: hasTileAt & better naming
This commit is contained in:
parent
1be6847a87
commit
74842aae1d
6 changed files with 43 additions and 12 deletions
|
@ -174,12 +174,12 @@ var Tilemap = new Class({
|
|||
return this.getIndex(this.layers, name);
|
||||
},
|
||||
|
||||
getTileAt: function (x, y, layer, nonNull)
|
||||
getTileAt: function (tileX, tileY, layer, nonNull)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
if (layer === null) { return null; }
|
||||
|
||||
return TilemapComponents.GetTileAt(x, y, layer, nonNull);
|
||||
return TilemapComponents.GetTileAt(tileX, tileY, layer, nonNull);
|
||||
},
|
||||
|
||||
getTilesetIndex: function (name)
|
||||
|
@ -187,6 +187,14 @@ var Tilemap = new Class({
|
|||
return this.getIndex(this.tilesets, name);
|
||||
},
|
||||
|
||||
hasTileAt: function (tileX, tileY, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
if (layer === null) { return null; }
|
||||
|
||||
return TilemapComponents.HasTileAt(tileX, tileY, layer);
|
||||
},
|
||||
|
||||
layer: {
|
||||
get: function ()
|
||||
{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
var GetTileAt = function (x, y, layer, nonNull)
|
||||
var GetTileAt = function (tileX, tileY, layer, nonNull)
|
||||
{
|
||||
if (nonNull === undefined) { nonNull = false; }
|
||||
|
||||
if (x >= 0 && x < layer.width && y >= 0 && y < layer.height)
|
||||
if (tileX >= 0 && tileX < layer.width && tileY >= 0 && tileY < layer.height)
|
||||
{
|
||||
var tile = layer.data[y][x];
|
||||
var tile = layer.data[tileY][tileX];
|
||||
if (tile.index === -1)
|
||||
{
|
||||
return nonNull ? tile : null;
|
||||
|
|
12
v3/src/gameobjects/tilemap/components/HasTileAt.js
Normal file
12
v3/src/gameobjects/tilemap/components/HasTileAt.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
var HasTileAt = function (tileX, tileY, layer)
|
||||
{
|
||||
if (layer.data[tileY] === undefined || layer.data[tileY][tileX] === undefined)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var tile = layer.data[tileY][tileX];
|
||||
return (tile !== null && tile.index > -1);
|
||||
};
|
||||
|
||||
module.exports = HasTileAt;
|
|
@ -1,5 +1,6 @@
|
|||
module.exports = {
|
||||
|
||||
GetTileAt: require('./GetTileAt')
|
||||
GetTileAt: require('./GetTileAt'),
|
||||
HasTileAt: require('./HasTileAt')
|
||||
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ var Class = require('../../../utils/Class');
|
|||
var GameObject = require('../../GameObject');
|
||||
var Components = require('../../components');
|
||||
var DynamicTilemapLayerRender = require('./DynamicTilemapLayerRender');
|
||||
var TileComponents = require('../components');
|
||||
var TilemapComponents = require('../components');
|
||||
|
||||
var DynamicTilemapLayer = new Class({
|
||||
|
||||
|
@ -96,9 +96,14 @@ var DynamicTilemapLayer = new Class({
|
|||
return culledTiles;
|
||||
},
|
||||
|
||||
getTileAt: function (x, y, nonNull)
|
||||
getTileAt: function (tileX, tileY, nonNull)
|
||||
{
|
||||
return TileComponents.GetTileAt(x, y, this.layer, nonNull);
|
||||
return TilemapComponents.GetTileAt(tileX, tileY, this.layer, nonNull);
|
||||
},
|
||||
|
||||
hasTileAt: function (tileX, tileY)
|
||||
{
|
||||
return TilemapComponents.HasTileAt(tileX, tileY, this.layer);
|
||||
}
|
||||
|
||||
// forEach: function (callback)
|
||||
|
|
|
@ -3,7 +3,7 @@ var GameObject = require('../../GameObject');
|
|||
var Components = require('../../components');
|
||||
var CONST = require('../../../renderer/webgl/renderers/tilemaprenderer/const');
|
||||
var StaticTilemapLayerRender = require('./StaticTilemapLayerRender');
|
||||
var TileComponents = require('../components');
|
||||
var TilemapComponents = require('../components');
|
||||
|
||||
var StaticTilemapLayer = new Class({
|
||||
|
||||
|
@ -269,9 +269,14 @@ var StaticTilemapLayer = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
getTileAt: function (x, y, nonNull)
|
||||
getTileAt: function (tileX, tileY, nonNull)
|
||||
{
|
||||
return TileComponents.GetTileAt(x, y, this.layer, nonNull);
|
||||
return TilemapComponents.GetTileAt(tileX, tileY, this.layer, nonNull);
|
||||
},
|
||||
|
||||
hasTileAt: function (tileX, tileY)
|
||||
{
|
||||
return TilemapComponents.HasTileAt(tileX, tileY, this.layer);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue