phaser/v3/src/gameobjects/tilemap/components/Fill.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

var GetTilesWithin = require('./GetTilesWithin');
var CalculateFacesWithin = require('./CalculateFacesWithin');
/**
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.
*
* @param {number} index - [description]
2017-11-27 13:33:30 +00:00
* @param {number} [tileX=0] - [description]
* @param {number} [tileY=0] - [description]
* @param {number} [width=max width based on tileX] - [description]
* @param {number} [height=max height based on tileY] - [description]
* @param {boolean} [recalculateFaces=true] - [description]
* @param {LayerData} layer - [description]
*/
var Fill = function (index, tileX, tileY, width, height, recalculateFaces, layer)
{
if (recalculateFaces === undefined) { recalculateFaces = true; }
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;
if (doesIndexCollide)
{
tiles[i].setCollision(true);
}
else
{
tiles[i].resetCollision();
}
}
if (recalculateFaces)
{
// Recalculate the faces within the area and neighboring tiles
CalculateFacesWithin(tileX - 1, tileY - 1, width + 2, height + 2, layer);
}
};
module.exports = Fill;