mirror of
https://github.com/photonstorm/phaser
synced 2024-12-23 11:33:28 +00:00
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
var GetTilesWithin = require('./GetTilesWithin');
|
|
|
|
/**
|
|
* Scans the given rectangular area (given in tile coordinates) for tiles with an index matching
|
|
* `indexA` and swaps then with `indexB`. This only modifies the index and does not change collision
|
|
* information.
|
|
*
|
|
* @param {integer} tileA - First tile index.
|
|
* @param {integer} tileB - Second tile index.
|
|
* @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]
|
|
* @param {LayerData} layer - [description]
|
|
*/
|
|
var SwapByIndex = function (indexA, indexB, tileX, tileY, width, height, layer)
|
|
{
|
|
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
|
|
for (var i = 0; i < tiles.length; i++)
|
|
{
|
|
if (tiles[i])
|
|
{
|
|
if (tiles[i].index === indexA)
|
|
{
|
|
tiles[i].index = indexB;
|
|
}
|
|
else if (tiles[i].index === indexB)
|
|
{
|
|
tiles[i].index = indexA;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = SwapByIndex;
|