forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFill.js
More file actions
47 lines (40 loc) · 1.87 KB
/
Copy pathFill.js
File metadata and controls
47 lines (40 loc) · 1.87 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
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var GetTilesWithin = require('./GetTilesWithin');
var CalculateFacesWithin = require('./CalculateFacesWithin');
var SetTileCollision = require('./SetTileCollision');
/**
* Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the
* specified index. Tiles will be set to collide if the given index is a colliding index.
* Collision information in the region will be recalculated.
*
* @function Phaser.Tilemaps.Components.Fill
* @since 3.0.0
*
* @param {integer} index - The tile index to fill the area with.
* @param {integer} tileX - The left most tile index (in tile coordinates) to use as the origin of the area.
* @param {integer} tileY - The top most tile index (in tile coordinates) to use as the origin of the area.
* @param {integer} width - How many tiles wide from the `tileX` index the area will be.
* @param {integer} height - How many tiles tall from the `tileY` index the area will be.
* @param {boolean} recalculateFaces - `true` if the faces data should be recalculated.
* @param {Phaser.Tilemaps.LayerData} layer - The tile layer to use. If not given the current layer is used.
*/
var Fill = function (index, tileX, tileY, width, height, recalculateFaces, layer)
{
var doesIndexCollide = (layer.collideIndexes.indexOf(index) !== -1);
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
for (var i = 0; i < tiles.length; i++)
{
tiles[i].index = index;
SetTileCollision(tiles[i], doesIndexCollide);
}
if (recalculateFaces)
{
// Recalculate the faces within the area and neighboring tiles
CalculateFacesWithin(tileX - 1, tileY - 1, width + 2, height + 2, layer);
}
};
module.exports = Fill;