2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2018-02-12 16:01:20 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-11-16 19:09:07 +00:00
|
|
|
var Tile = require('../Tile');
|
|
|
|
var IsInLayerBounds = require('./IsInLayerBounds');
|
2018-01-29 22:30:57 +00:00
|
|
|
var CalculateFacesAt = require('./CalculateFacesAt');
|
2017-11-16 19:09:07 +00:00
|
|
|
|
2017-11-27 13:33:30 +00:00
|
|
|
/**
|
|
|
|
* Removes the tile at the given tile coordinates in the specified layer and updates the layer's
|
|
|
|
* collision information.
|
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @function Phaser.Tilemaps.Components.RemoveTileAt
|
2018-04-16 14:25:22 +00:00
|
|
|
* @private
|
2018-02-08 01:08:59 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-08-20 11:20:23 +00:00
|
|
|
* @param {integer} tileX - The x coordinate.
|
|
|
|
* @param {integer} tileY - The y coordinate.
|
2018-09-28 13:32:36 +00:00
|
|
|
* @param {boolean} [replaceWithNull=true] - If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1.
|
|
|
|
* @param {boolean} [recalculateFaces=true] - `true` if the faces data should be recalculated.
|
2018-02-08 02:02:37 +00:00
|
|
|
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @return {Phaser.Tilemaps.Tile} The Tile object that was removed.
|
2017-11-27 13:33:30 +00:00
|
|
|
*/
|
2017-11-22 01:18:34 +00:00
|
|
|
var RemoveTileAt = function (tileX, tileY, replaceWithNull, recalculateFaces, layer)
|
2017-11-16 19:09:07 +00:00
|
|
|
{
|
|
|
|
if (replaceWithNull === undefined) { replaceWithNull = false; }
|
2017-11-22 01:18:34 +00:00
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
2017-11-16 19:09:07 +00:00
|
|
|
|
2019-03-05 14:41:35 +00:00
|
|
|
if (!IsInLayerBounds(tileX, tileY, layer))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tile = layer.data[tileY][tileX];
|
|
|
|
|
|
|
|
if (!tile)
|
2017-11-16 19:09:07 +00:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-05 14:41:35 +00:00
|
|
|
layer.data[tileY][tileX] = (replaceWithNull) ? null : new Tile(layer, -1, tileX, tileY, tile.width, tile.height);
|
2017-11-16 19:09:07 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 14:41:35 +00:00
|
|
|
// Recalculate faces only if the removed tile was a colliding tile
|
2017-11-22 01:18:34 +00:00
|
|
|
if (recalculateFaces && tile && tile.collides)
|
|
|
|
{
|
2018-01-29 22:30:57 +00:00
|
|
|
CalculateFacesAt(tileX, tileY, layer);
|
2017-11-22 01:18:34 +00:00
|
|
|
}
|
2017-11-16 19:09:07 +00:00
|
|
|
|
|
|
|
return tile;
|
|
|
|
};
|
|
|
|
|
2017-11-18 22:11:51 +00:00
|
|
|
module.exports = RemoveTileAt;
|