phaser/v3/src/gameobjects/tilemap/components/RemoveTileAt.js
2017-11-18 16:11:51 -06:00

28 lines
710 B
JavaScript

var Tile = require('../Tile');
var IsInLayerBounds = require('./IsInLayerBounds');
// Remove and return Tile with option for placing a -1 index tile or null.
var RemoveTileAt = function (tileX, tileY, replaceWithNull, layer)
{
if (replaceWithNull === undefined) { replaceWithNull = false; }
if (!IsInLayerBounds(tileX, tileY, layer)) { return null; }
var tile = layer.data[tileY][tileX];
if (tile === null)
{
return null;
}
else
{
layer.data[tileY][tileX] = replaceWithNull
? null
: new Tile(layer, -1, tileX, tileY, tile.width, tile.height);
}
// TODO: re-calculate faces
return tile;
};
module.exports = RemoveTileAt;