phaser/src/tilemaps/components/ForEachTile.js

48 lines
1.9 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}
*/
var GetTilesWithin = require('./GetTilesWithin');
2018-03-20 11:36:35 +00:00
/**
* @callback EachTileCallback
*
* @param {Phaser.Tilemaps.Tile} value - [description]
* @param {number} index - [description]
* @param {Phaser.Tilemaps.Tile[]} array - [description]
*/
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
* @private
2018-02-08 01:08:59 +00:00
* @since 3.0.0
*
2018-03-20 11:36:35 +00:00
* @param {EachTileCallback} callback - The callback. Each tile in the given area will be passed to this
2017-11-27 13:33:30 +00:00
* callback as the first and only parameter.
* @param {object} [context] - The context under which the callback should be run.
* @param {integer} [tileX=0] - [description]
* @param {integer} [tileY=0] - [description]
* @param {integer} [width=max width based on tileX] - [description]
* @param {integer} [height=max height based on tileY] - [description]
2017-11-27 13:33:30 +00:00
* @param {object} [filteringOptions] - Optional filters to apply when getting the tiles.
* @param {boolean} [filteringOptions.isNotEmpty=false] - If true, only return tiles that don't have
* -1 for an index.
2017-11-29 17:46:19 +00:00
* @param {boolean} [filteringOptions.isColliding=false] - If true, only return tiles that collide
* on at least one side.
2017-11-27 13:33:30 +00:00
* @param {boolean} [filteringOptions.hasInterestingFace=false] - If true, only return tiles that
* have at least one interesting face.
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
*/
var ForEachTile = function (callback, context, tileX, tileY, width, height, filteringOptions, layer)
{
var tiles = GetTilesWithin(tileX, tileY, width, height, filteringOptions, layer);
tiles.forEach(callback, context);
};
module.exports = ForEachTile;