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

24 lines
693 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`.
*
* @param {number} tileIndex - [description]
* @param {boolean} [collides=true] - [description]
* @param {LayerData} layer - [description]
*/
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;