World#iterate()

iterate(key, value, returnType, callback, callbackContext, args) → {any}

Iterates over the children of the group performing one of several actions for matched children.

A child is considered a match when it has a property, named key, whose value is equal to value
according to a strict equality comparison.

The result depends on the returnType:

  • RETURN_TOTAL:
    The callback, if any, is applied to all matching children. The number of matched children is returned.
  • RETURN_NONE:
    The callback, if any, is applied to all matching children. No value is returned.
  • RETURN_CHILD:
    The callback, if any, is applied to the first matching child and the first matched child is returned.
    If there is no matching child then null is returned.

If args is specified it must be an array. The matched child will be assigned to the first
element and the entire array will be applied to the callback function.

Parameters
Name Type Argument Default Description
key string

The child property to check, i.e. 'exists', 'alive', 'health'

value any

A child matches if child[key] === value is true.

returnType integer

How to iterate the children and what to return.

callback function <optional>
null

Optional function that will be called on each matching child. The matched child is supplied as the first argument.

callbackContext object <optional>

The context in which the function should be called (usually 'this').

args Array.<any> <optional>
(none)

The arguments supplied to to the callback; the first array index (argument) will be replaced with the matched child.

Returns
any -

Returns either an integer (for RETURN_TOTAL), the first matched child (for RETURN_CHILD), or null.

Inherited From
Source code: core/Group.js (Line 1976)
doc_phaser
2017-02-14 11:21:15
Comments
Leave a Comment

Please login to continue.