2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2022-02-28 14:29:51 +00:00
|
|
|
* @copyright 2022 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-17 01:08:58 +00:00
|
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
2017-11-15 22:36:41 +00:00
|
|
|
|
2018-03-20 11:36:35 +00:00
|
|
|
/**
|
|
|
|
* @callback EachTileCallback
|
|
|
|
*
|
2018-09-28 13:32:36 +00:00
|
|
|
* @param {Phaser.Tilemaps.Tile} value - The Tile.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} index - The index of the tile.
|
2018-09-28 13:32:36 +00:00
|
|
|
* @param {Phaser.Tilemaps.Tile[]} array - An array of Tile objects.
|
2018-03-20 11:36:35 +00:00
|
|
|
*/
|
|
|
|
|
2017-11-26 15:33:19 +00:00
|
|
|
/**
|
2017-11-27 13:33:30 +00:00
|
|
|
* For each tile in the given rectangular area (in tile coordinates) of the layer, run the given
|
2017-11-29 17:46:19 +00:00
|
|
|
* callback. Similar to Array.prototype.forEach in vanilla JS.
|
2017-11-27 13:33:30 +00:00
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @function Phaser.Tilemaps.Components.ForEachTile
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 13:32:36 +00:00
|
|
|
* @param {EachTileCallback} callback - The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
|
2020-11-23 10:54:14 +00:00
|
|
|
* @param {object} context - The context under which the callback should be run.
|
|
|
|
* @param {number} tileX - The left most tile index (in tile coordinates) to use as the origin of the area to filter.
|
|
|
|
* @param {number} tileY - The top most tile index (in tile coordinates) to use as the origin of the area to filter.
|
|
|
|
* @param {number} width - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} height - How many tiles tall from the `tileY` index the area will be.
|
|
|
|
* @param {Phaser.Types.Tilemaps.FilteringOptions} filteringOptions - Optional filters to apply when getting the tiles.
|
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
|
|
|
*/
|
2017-11-26 00:03:21 +00:00
|
|
|
var ForEachTile = function (callback, context, tileX, tileY, width, height, filteringOptions, layer)
|
2017-11-15 22:36:41 +00:00
|
|
|
{
|
2017-11-26 00:03:21 +00:00
|
|
|
var tiles = GetTilesWithin(tileX, tileY, width, height, filteringOptions, layer);
|
2018-09-28 13:32:36 +00:00
|
|
|
|
2017-11-15 22:36:41 +00:00
|
|
|
tiles.forEach(callback, context);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ForEachTile;
|