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-29 14:20:24 +00:00
|
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
|
|
|
|
|
|
|
/**
|
2018-02-08 01:08:59 +00:00
|
|
|
* Sets a collision callback for the given rectangular area (in tile coordinates) within the layer.
|
2017-11-29 14:20:24 +00:00
|
|
|
* If a callback is already set for the tile index it will be replaced. Set the callback to null to
|
|
|
|
* remove it.
|
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @function Phaser.Tilemaps.Components.SetTileLocationCallback
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 13:32:36 +00:00
|
|
|
* @param {integer} [tileX=0] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {integer} [tileY=0] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {integer} [width=max width based on tileX] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {integer} [height=max height based on tileY] - How many tiles tall from the `tileY` index the area will be.
|
2017-11-29 14:20:24 +00:00
|
|
|
* @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 14:20:24 +00:00
|
|
|
*/
|
|
|
|
var SetTileLocationCallback = function (tileX, tileY, width, height, callback, callbackContext, layer)
|
|
|
|
{
|
|
|
|
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
|
|
|
|
|
|
|
|
for (var i = 0; i < tiles.length; i++)
|
|
|
|
{
|
|
|
|
tiles[i].setCollisionCallback(callback, callbackContext);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SetTileLocationCallback;
|