phaser/src/tilemaps/components/SetLayerCollisionIndex.js

33 lines
1 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2020-01-15 12:07:09 +00:00
* @copyright 2020 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +00:00
*/
2017-11-27 13:33:30 +00:00
/**
* Internally used method to keep track of the tile indexes that collide within a layer. This
* updates LayerData.collideIndexes to either contain or not contain the given `tileIndex`.
*
2018-02-08 01:08:59 +00:00
* @function Phaser.Tilemaps.Components.SetLayerCollisionIndex
* @since 3.0.0
*
2020-11-23 10:22:13 +00:00
* @param {number} tileIndex - The tile index to set the collision boolean for.
2020-11-23 10:48:24 +00:00
* @param {boolean} collides - Should the tile index collide or not?
2018-02-08 02:02:37 +00:00
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
2017-11-27 13:33:30 +00:00
*/
var SetLayerCollisionIndex = function (tileIndex, collides, layer)
{
var loc = layer.collideIndexes.indexOf(tileIndex);
if (collides && loc === -1)
{
layer.collideIndexes.push(tileIndex);
}
else if (!collides && loc !== -1)
{
layer.collideIndexes.splice(loc, 1);
}
};
module.exports = SetLayerCollisionIndex;