Groups: Added the index parameter to the end of the parameter list for the forEach callback that indicates the index of the child that is being iterated

This commit is contained in:
Vaughan Hilts 2016-11-16 21:11:13 -05:00
parent 6a81bcb590
commit 8b20045cba

View file

@ -138,11 +138,11 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
this.cursor = null;
/**
* A Group with `inputEnableChildren` set to `true` will automatically call `inputEnabled = true`
* A Group with `inputEnableChildren` set to `true` will automatically call `inputEnabled = true`
* on any children _added_ to, or _created by_, this Group.
*
*
* If there are children already in the Group at the time you set this property, they are not changed.
*
*
* @property {boolean} inputEnableChildren
* @default
*/
@ -152,10 +152,10 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
* This Signal is dispatched whenever a child of this Group emits an onInputDown signal as a result
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
* every child Sprite.
*
*
* This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and
* a reference to the Pointer that caused it.
*
*
* @property {Phaser.Signal} onChildInputDown
*/
this.onChildInputDown = new Phaser.Signal();
@ -164,11 +164,11 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
* This Signal is dispatched whenever a child of this Group emits an onInputUp signal as a result
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
* every child Sprite.
*
* This Signal is sent 3 arguments: A reference to the Sprite that triggered the signal,
*
* This Signal is sent 3 arguments: A reference to the Sprite that triggered the signal,
* a reference to the Pointer that caused it, and a boolean value `isOver` that tells you if the Pointer
* is still over the Sprite or not.
*
*
* @property {Phaser.Signal} onChildInputUp
*/
this.onChildInputUp = new Phaser.Signal();
@ -177,10 +177,10 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
* This Signal is dispatched whenever a child of this Group emits an onInputOver signal as a result
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
* every child Sprite.
*
*
* This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and
* a reference to the Pointer that caused it.
*
*
* @property {Phaser.Signal} onChildInputOver
*/
this.onChildInputOver = new Phaser.Signal();
@ -189,10 +189,10 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
* This Signal is dispatched whenever a child of this Group emits an onInputOut signal as a result
* of having been interacted with by a Pointer. You can bind functions to this Signal instead of to
* every child Sprite.
*
*
* This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and
* a reference to the Pointer that caused it.
*
*
* @property {Phaser.Signal} onChildInputOut
*/
this.onChildInputOut = new Phaser.Signal();
@ -227,8 +227,8 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
/**
* If this Group contains Arcade Physics Sprites you can set a custom sort direction via this property.
*
* It should be set to one of the Phaser.Physics.Arcade sort direction constants:
*
* It should be set to one of the Phaser.Physics.Arcade sort direction constants:
*
* Phaser.Physics.Arcade.SORT_NONE
* Phaser.Physics.Arcade.LEFT_RIGHT
* Phaser.Physics.Arcade.RIGHT_LEFT
@ -236,7 +236,7 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
* Phaser.Physics.Arcade.BOTTOM_TOP
*
* If set to `null` the Group will use whatever Phaser.Physics.Arcade.sortDirection is set to. This is the default behavior.
*
*
* @property {integer} physicsSortDirection
* @default
*/
@ -256,10 +256,10 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
/**
* A Group that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Group.cameraOffset.
*
*
* Note that the cameraOffset values are in addition to any parent in the display list.
* So if this Group was in a Group that has x: 200, then this will be added to the cameraOffset.x
*
*
* @property {boolean} fixedToCamera
*/
this.fixedToCamera = false;
@ -273,13 +273,13 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
/**
* The hash array is an array belonging to this Group into which you can add any of its children via Group.addToHash and Group.removeFromHash.
*
*
* Only children of this Group can be added to and removed from the hash.
*
*
* This hash is used automatically by Phaser Arcade Physics in order to perform non z-index based destructive sorting.
* However if you don't use Arcade Physics, or this isn't a physics enabled Group, then you can use the hash to perform your own
* sorting and filtering of Group children without touching their z-index (and therefore display draw order)
*
*
* @property {array} hash
*/
this.hash = [];
@ -343,7 +343,7 @@ Phaser.Group.SORT_DESCENDING = 1;
*
* The child is automatically added to the top of the group, and is displayed above every previous child.
*
* Or if the _optional_ index is specified, the child is added at the location specified by the index value,
* Or if the _optional_ index is specified, the child is added at the location specified by the index value,
* this allows you to control child ordering.
*
* If the child was already in this Group, it is simply returned, and nothing else happens to it.
@ -419,7 +419,7 @@ Phaser.Group.prototype.add = function (child, silent, index) {
* Adds an existing object to this group.
*
* The child is added to the group at the location specified by the index value, this allows you to control child ordering.
*
*
* If `Group.enableBody` is set, then a physics body will be created on the object, so long as one does not already exist.
*
* If `Group.inputEnableChildren` is set, then an Input Handler will be created on the object, so long as one does not already exist.
@ -493,7 +493,7 @@ Phaser.Group.prototype.removeFromHash = function (child) {
*
* As well as an array you can also pass another Group as the first argument. In this case all of the children from that
* Group will be removed from it and added into this Group.
*
*
* If `Group.enableBody` is set, then a physics body will be created on the objects, so long as one does not already exist.
*
* If `Group.inputEnableChildren` is set, then an Input Handler will be created on the objects, so long as one does not already exist.
@ -545,12 +545,12 @@ Phaser.Group.prototype.getAt = function (index) {
* Creates a new Phaser.Sprite object and adds it to the top of this group.
*
* Use {@link #classType} to change the type of object created.
*
*
* The child is automatically added to the top of the group, and is displayed above every previous child.
*
* Or if the _optional_ index is specified, the child is added at the location specified by the index value,
* Or if the _optional_ index is specified, the child is added at the location specified by the index value,
* this allows you to control child ordering.
*
*
* If `Group.enableBody` is set, then a physics body will be created on the object, so long as one does not already exist.
*
* If `Group.inputEnableChildren` is set, then an Input Handler will be created on the object, so long as one does not already exist.
@ -580,16 +580,16 @@ Phaser.Group.prototype.create = function (x, y, key, frame, exists, index) {
/**
* Creates multiple Phaser.Sprite objects and adds them to the top of this Group.
*
*
* This method is useful if you need to quickly generate a pool of sprites, such as bullets.
*
* Use {@link #classType} to change the type of object created.
*
* You can provide an array as the `key` and / or `frame` arguments. When you do this
* it will create `quantity` Sprites for every key (and frame) in the arrays.
*
*
* For example:
*
*
* `createMultiple(25, ['ball', 'carrot'])`
*
* In the above code there are 2 keys (ball and carrot) which means that 50 sprites will be
@ -611,9 +611,9 @@ Phaser.Group.prototype.create = function (x, y, key, frame, exists, index) {
* It will then create 20 'balls' of frame 0, 20 with frame 1 and 20 with frame 2.
* In total it will have created 120 sprites.
*
* By default the Sprites will have their `exists` property set to `false`, and they will be
* By default the Sprites will have their `exists` property set to `false`, and they will be
* positioned at 0x0, relative to the `Group.x / y` values.
*
*
* If `Group.enableBody` is set, then a physics body will be created on the objects, so long as one does not already exist.
*
* If `Group.inputEnableChildren` is set, then an Input Handler will be created on the objects, so long as one does not already exist.
@ -694,7 +694,7 @@ Phaser.Group.prototype.updateZ = function () {
*
* This will align all of the children into a grid formation of 10x10, using 32 pixels per
* grid cell. If you want a wider grid, you could do:
*
*
* `Group.align(25, 4, 32, 32)`
*
* This will align the children into a grid of 25x4, again using 32 pixels per grid cell.
@ -705,19 +705,19 @@ Phaser.Group.prototype.updateZ = function () {
*
* `Group.align(-1, 8, 32, 32)`
*
* ... will align the children so that there are 8 children vertically (the second argument),
* ... will align the children so that there are 8 children vertically (the second argument),
* and each row will contain 6 sprites, except the last one, which will contain 5 (totaling 48)
*
* You can also do:
*
*
* `Group.align(10, -1, 32, 32)`
*
* In this case it will create a grid 10 wide, and as tall as it needs to be in order to fit
* all of the children in.
*
* The `position` property allows you to control where in each grid cell the child is positioned.
* This is a constant and can be one of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`,
* `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`,
* This is a constant and can be one of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`,
* `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`,
* `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
*
* The final argument; `offset` lets you start the alignment from a specific child index.
@ -1726,10 +1726,10 @@ Phaser.Group.prototype.filter = function (predicate, checkExists) {
* Note: This check will skip any children which are Groups themselves.
*
* @method Phaser.Group#forEach
* @param {function} callback - The function that will be called for each applicable child. The child will be passed as the first argument.
* @param {function} callback - The function that will be called for each applicable child. The child will be passed as the first argument and the index of that child as the second argument.
* @param {object} callbackContext - The context in which the function should be called (usually 'this').
* @param {boolean} [checkExists=false] - If set only children matching for which `exists` is true will be passed to the callback, otherwise all children will be passed.
* @param {...any} [args=(none)] - Additional arguments to pass to the callback function, after the child item.
* @param {...any} [args=(none)] - Additional arguments to pass to the callback function, after the other parameters.
*/
Phaser.Group.prototype.forEach = function (callback, callbackContext, checkExists) {
@ -1741,7 +1741,7 @@ Phaser.Group.prototype.forEach = function (callback, callbackContext, checkExist
{
if (!checkExists || (checkExists && this.children[i].exists))
{
callback.call(callbackContext, this.children[i]);
callback.call(callbackContext, this.children[i], i);
}
}
}
@ -1761,7 +1761,7 @@ Phaser.Group.prototype.forEach = function (callback, callbackContext, checkExist
if (!checkExists || (checkExists && this.children[i].exists))
{
args[0] = this.children[i];
callback.apply(callbackContext, args);
callback.apply(callbackContext, args.concat([i]));
}
}
}
@ -1856,7 +1856,7 @@ Phaser.Group.prototype.forEachDead = function (callback, callbackContext) {
* Sort the children in the group according to a particular key and ordering.
*
* Call this function to sort the group according to a particular key value and order.
*
*
* For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`.
*
* Internally this uses a standard JavaScript Array sort, so everything that applies there also applies here, including
@ -2070,7 +2070,7 @@ Phaser.Group.prototype.iterate = function (key, value, returnType, callback, cal
/**
* Get the first display object that exists, or doesn't exist.
*
*
* You can use the optional argument `createIfNull` to create a new Game Object if none matching your exists argument were found in this Group.
*
* It works by calling `Group.create` passing it the parameters given to this method, and returning the new child.
@ -2244,7 +2244,7 @@ Phaser.Group.prototype.getBottom = function () {
*
* You can use the optional `callback` argument to apply your own filter to the distance checks.
* If the child is closer then the previous child, it will be sent to `callback` as the first argument,
* with the distance as the second. The callback should return `true` if it passes your
* with the distance as the second. The callback should return `true` if it passes your
* filtering criteria, otherwise it should return `false`.
*
* @method Phaser.Group#getClosestTo
@ -2288,7 +2288,7 @@ Phaser.Group.prototype.getClosestTo = function (object, callback, callbackContex
*
* You can use the optional `callback` argument to apply your own filter to the distance checks.
* If the child is closer then the previous child, it will be sent to `callback` as the first argument,
* with the distance as the second. The callback should return `true` if it passes your
* with the distance as the second. The callback should return `true` if it passes your
* filtering criteria, otherwise it should return `false`.
*
* @method Phaser.Group#getFurthestFrom
@ -2509,7 +2509,7 @@ Phaser.Group.prototype.moveAll = function (group, silent) {
* Removes all children from this Group, but does not remove the group from its parent.
*
* The children can be optionally destroyed as they are removed.
*
*
* You can also optionally also destroy the BaseTexture the Child is using. Be careful if you've
* more than one Game Object sharing the same BaseTexture.
*
@ -2666,7 +2666,7 @@ Object.defineProperty(Phaser.Group.prototype, "total", {
* Total number of children in this group, regardless of exists/alive status.
*
* @name Phaser.Group#length
* @property {integer} length
* @property {integer} length
* @readonly
*/
Object.defineProperty(Phaser.Group.prototype, "length", {
@ -2707,7 +2707,7 @@ Object.defineProperty(Phaser.Group.prototype, "angle", {
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
*
* @name Phaser.Group#centerX
* @property {number} centerX
*/
@ -2735,7 +2735,7 @@ Object.defineProperty(Phaser.Group.prototype, "centerX", {
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
*
* @name Phaser.Group#centerY
* @property {number} centerY
*/
@ -2763,7 +2763,7 @@ Object.defineProperty(Phaser.Group.prototype, "centerY", {
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
*
* @name Phaser.Group#left
* @property {number} left
*/
@ -2847,7 +2847,7 @@ Object.defineProperty(Phaser.Group.prototype, "top", {
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
*
* @name Phaser.Group#bottom
* @property {number} bottom
*/
@ -2875,17 +2875,17 @@ Object.defineProperty(Phaser.Group.prototype, "bottom", {
* 'container', to one of 9 possible positions.
*
* The container must be a Game Object, or Phaser.Rectangle object. This can include properties
* such as `World.bounds` or `Camera.view`, for aligning Groups within the world
* such as `World.bounds` or `Camera.view`, for aligning Groups within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Group to another Game Object does **not** make it a child of
* the container. It simply modifies its position coordinates so it aligns with it.
*
*
* The position constants you can use are:
*
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`,
* `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`,
*
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`,
* `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`,
* `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
*
* Groups are placed in such a way that their _bounds_ align with the
@ -2917,18 +2917,18 @@ Object.defineProperty(Phaser.Group.prototype, "bottom", {
* 'parent', in one of 11 possible positions.
*
* The parent must be a Game Object, or Phaser.Rectangle object. This can include properties
* such as `World.bounds` or `Camera.view`, for aligning Groups within the world
* such as `World.bounds` or `Camera.view`, for aligning Groups within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Group to another Game Object does **not** make it a child of
* the parent. It simply modifies its position coordinates so it aligns with it.
*
*
* The position constants you can use are:
*
* `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`,
* `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`,
* `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER`
*
* `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`,
* `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`,
* `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER`
* and `Phaser.BOTTOM_RIGHT`.
*
* Groups are placed in such a way that their _bounds_ align with the