2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-11-16 02:06:07 +00:00
|
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
2017-11-26 15:19:57 +00:00
|
|
|
var CalculateFacesWithin = require('./CalculateFacesWithin');
|
2018-01-29 22:51:08 +00:00
|
|
|
var SetTileCollision = require('./SetTileCollision');
|
2017-11-26 15:19:57 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-26 15:33:19 +00:00
|
|
|
* 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.
|
2017-11-27 13:33:30 +00:00
|
|
|
* Collision information in the region will be recalculated.
|
2017-11-26 15:19:57 +00:00
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @function Phaser.Tilemaps.Components.Fill
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2017-11-29 21:07:56 +00:00
|
|
|
* @param {integer} index - [description]
|
|
|
|
* @param {integer} [tileX=0] - [description]
|
|
|
|
* @param {integer} [tileY=0] - [description]
|
|
|
|
* @param {integer} [width=max width based on tileX] - [description]
|
|
|
|
* @param {integer} [height=max height based on tileY] - [description]
|
2017-11-26 15:19:57 +00:00
|
|
|
* @param {boolean} [recalculateFaces=true] - [description]
|
2018-02-08 02:02:37 +00:00
|
|
|
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
2017-11-26 15:19:57 +00:00
|
|
|
*/
|
|
|
|
var Fill = function (index, tileX, tileY, width, height, recalculateFaces, layer)
|
2017-11-16 02:06:07 +00:00
|
|
|
{
|
2017-11-26 15:19:57 +00:00
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
|
|
|
var doesIndexCollide = (layer.collideIndexes.indexOf(index) !== -1);
|
|
|
|
|
2017-11-26 00:03:21 +00:00
|
|
|
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
|
2017-11-16 02:06:07 +00:00
|
|
|
for (var i = 0; i < tiles.length; i++)
|
|
|
|
{
|
|
|
|
tiles[i].index = index;
|
2017-11-26 15:19:57 +00:00
|
|
|
|
2018-01-29 22:51:08 +00:00
|
|
|
SetTileCollision(tiles[i], doesIndexCollide);
|
2017-11-26 15:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (recalculateFaces)
|
|
|
|
{
|
|
|
|
// Recalculate the faces within the area and neighboring tiles
|
|
|
|
CalculateFacesWithin(tileX - 1, tileY - 1, width + 2, height + 2, layer);
|
2017-11-16 02:06:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Fill;
|