phaser/src/tilemaps/components/SetTileIndexCallback.js

43 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2017-11-29 13:53:04 +00:00
/**
* Sets a global collision callback for the given tile index within the layer. This will affect all
* tiles on this layer that have the same index. If a callback is already set for the tile index it
* will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile
* at a specific location on the map then see setTileLocationCallback.
*
2018-02-08 01:08:59 +00:00
* @function Phaser.Tilemaps.Components.SetTileIndexCallback
* @private
2018-02-08 01:08:59 +00:00
* @since 3.0.0
*
2018-03-20 15:11:33 +00:00
* @param {(integer|array)} indexes - Either a single tile index, or an array of tile indexes to have a
2017-11-29 13:53:04 +00:00
* collision callback set for.
* @param {function} callback - The callback that will be invoked when the tile is collided with.
* @param {object} callbackContext - The context under which the callback is called.
2018-02-08 02:02:37 +00:00
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
2017-11-29 13:53:04 +00:00
*/
var SetTileIndexCallback = function (indexes, callback, callbackContext, layer)
{
if (typeof indexes === 'number')
{
layer.callbacks[indexes] = (callback !== null)
? { callback: callback, callbackContext: callbackContext }
: undefined;
}
else
{
for (var i = 0, len = indexes.length; i < len; i++)
{
layer.callbacks[indexes[i]] = (callback !== null)
? { callback: callback, callbackContext: callbackContext }
: undefined;
}
}
};
module.exports = SetTileIndexCallback;