forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveTileAt.js
More file actions
57 lines (49 loc) · 1.76 KB
/
Copy pathRemoveTileAt.js
File metadata and controls
57 lines (49 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Tile = require('../Tile');
var IsInLayerBounds = require('./IsInLayerBounds');
var CalculateFacesAt = require('./CalculateFacesAt');
/**
* Removes the tile at the given tile coordinates in the specified layer and updates the layer's
* collision information.
*
* @function Phaser.Tilemaps.Components.RemoveTileAt
* @private
* @since 3.0.0
*
* @param {integer} tileX - The x coordinate.
* @param {integer} tileY - The y coordinate.
* @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.
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
*
* @return {Phaser.Tilemaps.Tile} The Tile object that was removed.
*/
var RemoveTileAt = function (tileX, tileY, replaceWithNull, recalculateFaces, layer)
{
if (replaceWithNull === undefined) { replaceWithNull = false; }
if (recalculateFaces === undefined) { recalculateFaces = true; }
if (!IsInLayerBounds(tileX, tileY, layer))
{
return null;
}
var tile = layer.data[tileY][tileX];
if (!tile)
{
return null;
}
else
{
layer.data[tileY][tileX] = (replaceWithNull) ? null : new Tile(layer, -1, tileX, tileY, tile.width, tile.height);
}
// Recalculate faces only if the removed tile was a colliding tile
if (recalculateFaces && tile && tile.collides)
{
CalculateFacesAt(tileX, tileY, layer);
}
return tile;
};
module.exports = RemoveTileAt;