phaser/src/tilemaps/components/SetLayerCollisionIndex.js

27 lines
792 B
JavaScript
Raw Normal View History

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
*
* @param {integer} tileIndex - [description]
2017-11-27 13:33:30 +00:00
* @param {boolean} [collides=true] - [description]
2018-02-08 01:08:59 +00:00
* @param {Phaser.Tilemaps.LayerData} layer - [description]
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;