Class: Group

Phaser. Group

A Group is a container for display objects that allows for fast pooling, recycling and collision checks.

new Group(game, parent, name, useStage)

Phaser Group constructor.
Parameters:
Name Type Description
game Phaser.Game A reference to the currently running game.
parent Description Description.
name string The unique name for this animation, used in playback commands.
useStage boolean Description.
Source:
  • core/Group.js, line 18

Members

exists

Properties:
Name Type Description
exists boolean Description.
Default Value:
  • true
Source:
  • core/Group.js, line 72

game

Properties:
Name Type Description
game Phaser.Game A reference to the currently running Game.
Source:
  • core/Group.js, line 30

name

Properties:
Name Type Description
name Phaser.Game Description.
Source:
  • core/Group.js, line 35

type

Properties:
Name Type Description
type Description Description.
Source:
  • core/Group.js, line 66

Methods

<static> add(child) → {Description}

Description.
Parameters:
Name Type Description
child Description Description.
Source:
  • core/Group.js, line 85
Returns:
Description.
Type
Description

<static> addAll(property, amount, checkAlive, checkVisible)

Adds the amount to the given property on all children in this Group. Group.addAll('x', 10) will add 10 to the child.x value.
Parameters:
Name Type Description
property string The property to increment, for example 'body.velocity.x' or 'angle'.
amount number The amount to increment the property by. If child.x = 10 then addAll('x', 40) would make child.x = 50.
checkAlive boolean If true the property will only be changed if the child is alive.
checkVisible boolean If true the property will only be changed if the child is visible.
Source:
  • core/Group.js, line 481

<static> addAt(child, index) → {Description}

Description.
Parameters:
Name Type Description
child Description Description.
index Description Description.
Source:
  • core/Group.js, line 111
Returns:
Description.
Type
Description

<static> bringToTop(child) → {Description}

Description.
Parameters:
Name Type Description
child Description Description.
Source:
  • core/Group.js, line 313
Returns:
Description.
Type
Description

<static> callAll(callback, parameter)

Calls a function on all of the children regardless if they are dead or alive (see callAllExists if you need control over that) After the callback parameter you can add as many extra parameters as you like, which will all be passed to the child.
Parameters:
Name Type Argument Description
callback function The function that exists on the children that will be called.
parameter * <repeatable>
Additional parameters that will be passed to the callback.
Source:
  • core/Group.js, line 582

<static> callAllExists(callback, existsValue, parameter)

Calls a function on all of the children that have exists=true in this Group. After the existsValue parameter you can add as many parameters as you like, which will all be passed to the child callback.
Parameters:
Name Type Argument Description
callback function The function that exists on the children that will be called.
existsValue boolean Only children with exists=existsValue will be called.
parameter * <repeatable>
Additional parameters that will be passed to the callback.
Source:
  • core/Group.js, line 549

<static> countDead() → {number}

Call this function to find out how many members of the group are dead.
Source:
  • core/Group.js, line 845
Returns:
The number of children flagged as dead. Returns -1 if Group is empty.
Type
number

<static> countLiving() → {number}

Call this function to find out how many members of the group are alive.
Source:
  • core/Group.js, line 814
Returns:
The number of children flagged as alive. Returns -1 if Group is empty.
Type
number

<static> create(x, y, key, frame, exists) → {Description}

Description.
Parameters:
Name Type Argument Description
x number Description.
y number Description.
key string Description.
frame string <optional>
Description.
exists boolean <optional>
Description.
Source:
  • core/Group.js, line 152
Returns:
Description.
Type
Description

<static> destroy()

Description.
Source:
  • core/Group.js, line 968

<static> divideAll(property, amount, checkAlive, checkVisible)

Divides the given property by the amount on all children in this Group. Group.divideAll('x', 2) will half the child.x value.
Parameters:
Name Type Description
property string The property to divide, for example 'body.velocity.x' or 'angle'.
amount number The amount to divide the property by. If child.x = 100 then divideAll('x', 2) would make child.x = 50.
checkAlive boolean If true the property will only be changed if the child is alive.
checkVisible boolean If true the property will only be changed if the child is visible.
Source:
  • core/Group.js, line 532

<static> dump()

Description.
Source:
  • core/Group.js, line 988

<static> forEach(callback, callbackContext, checkExists)

Description. After the checkExists parameter you can add as many parameters as you like, which will all be passed to the callback along with the child.
Parameters:
Name Type Description
callback Description Description.
callbackContext Description Description.
checkExists boolean Description.
Source:
  • core/Group.js, line 614

<static> forEachAlive(callback, callbackContext)

Description.
Parameters:
Name Type Description
callback Description Description.
callbackContext Description Description.
Source:
  • core/Group.js, line 654

<static> forEachDead(callback, callbackContext)

Description.
Parameters:
Name Type Description
callback Description Description.
callbackContext Description Description.
Source:
  • core/Group.js, line 687

<static> getAt(index) → {Description}

Description.
Parameters:
Name Type Description
index Description Description.
Source:
  • core/Group.js, line 138
Returns:
Description.
Type
Description

<static> getFirstAlive() → {Any}

Call this function to retrieve the first object with alive == true in the group. This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
Source:
  • core/Group.js, line 754
Returns:
The first alive child, or null if none found.
Type
Any

<static> getFirstDead() → {Any}

Call this function to retrieve the first object with alive == false in the group. This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
Source:
  • core/Group.js, line 784
Returns:
The first dead child, or null if none found.
Type
Any

<static> getFirstExists(state) → {Any}

Call this function to retrieve the first object with exists == (the given state) in the group.
Parameters:
Name Type Description
state Description Description.
Source:
  • core/Group.js, line 719
Returns:
The first child, or null if none found.
Type
Any

<static> getIndex(child) → {Description}

Description.
Parameters:
Name Type Description
child Description Description.
Source:
  • core/Group.js, line 333
Returns:
Description.
Type
Description

<static> getRandom(startIndex, length) → {Any}

Returns a member at random from the group.
Parameters:
Name Type Description
startIndex number Optional offset off the front of the array. Default value is 0, or the beginning of the array.
length number Optional restriction on the number of values you want to randomly select from.
Source:
  • core/Group.js, line 876
Returns:
A random child of this Group.
Type
Any

<static> multiplyAll(property, amount, checkAlive, checkVisible)

Multiplies the given property by the amount on all children in this Group. Group.multiplyAll('x', 2) will x2 the child.x value.
Parameters:
Name Type Description
property string The property to multiply, for example 'body.velocity.x' or 'angle'.
amount number The amount to multiply the property by. If child.x = 10 then multiplyAll('x', 2) would make child.x = 20.
checkAlive boolean If true the property will only be changed if the child is alive.
checkVisible boolean If true the property will only be changed if the child is visible.
Source:
  • core/Group.js, line 515

<static> remove(child)

Description.
Parameters:
Name Type Description
child Description Description.
Source:
  • core/Group.js, line 899

<static> removeAll()

Description.
Source:
  • core/Group.js, line 914

<static> removeBetween(startIndex, endIndex)

Description.
Parameters:
Name Type Description
startIndex Description Description.
endIndex Description Description.
Source:
  • core/Group.js, line 939

<static> replace(oldChild, newChild)

Description.
Parameters:
Name Type Description
oldChild Description Description.
newChild Description Description.
Source:
  • core/Group.js, line 347

<static> setAll(key, value, checkAlive, checkVisible, operation)

Description.
Parameters:
Name Type Description
key Description Description.
value Description Description.
checkAlive Description Description.
checkVisible Description Description.
operation Description Description.
Source:
  • core/Group.js, line 443

<static> setProperty(child, key, value, operation) → {number}

Description.
Parameters:
Name Type Description
child Description Description.
key array An array of values that will be set.
value Description Description.
operation Description Description.
Source:
  • core/Group.js, line 379
Returns:
An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2). (TODO)
Type
number

<static> subAll(property, amount, checkAlive, checkVisible)

Subtracts the amount from the given property on all children in this Group. Group.subAll('x', 10) will minus 10 from the child.x value.
Parameters:
Name Type Description
property string The property to decrement, for example 'body.velocity.x' or 'angle'.
amount number The amount to subtract from the property. If child.x = 50 then subAll('x', 40) would make child.x = 10.
checkAlive boolean If true the property will only be changed if the child is alive.
checkVisible boolean If true the property will only be changed if the child is visible.
Source:
  • core/Group.js, line 498

<static> swap(child1, child2) → {boolean}

Description.
Parameters:
Name Type Description
child1 Description Description.
child2 Description Description.
Source:
  • core/Group.js, line 184
Returns:
Description.
Type
boolean