new BodyDebug(game, body, settings)
Draws a P2 Body to a Graphics instance for visual debugging. Needless to say, for every body you enable debug drawing on, you are adding processor and graphical overhead. So use sparingly and rarely (if ever) in production code.
Parameters:
| Name | Type | Description |
|---|---|---|
game |
Phaser.Game | Game reference to the currently running game. |
body |
Phaser.Physics.P2.Body | The P2 Body to display debug data for. |
settings |
object | Settings object. |
- Source:
Extends
Members
-
alive
-
- Inherited From:
- Default Value:
- true
- Source:
Properties:
Name Type Description aliveboolean The alive property is useful for Groups that are children of other Groups and need to be included/excluded in checks like forEachAlive.
-
alpha
-
- Inherited From:
- Source:
Properties:
Name Type Description alphanumber The alpha value of the Group container.
-
angle
-
The angle of rotation of the Group container. This will adjust the Group container itself by modifying its rotation. This will have no impact on the rotation value of its children, but it will update their worldTransform and on-screen position.
- Inherited From:
- Source:
Properties:
Name Type Description anglenumber The angle of rotation given in degrees, where 0 degrees = to the right.
-
body
-
- Source:
Properties:
Name Type Description bodyPhaser.Physics.P2.Body The P2 Body to display debug data for.
-
cameraOffset
-
- Inherited From:
- Source:
Properties:
Name Type Description cameraOffsetPhaser.Point If this object is fixedToCamera then this stores the x/y offset that its drawn at, from the top-left of the camera view.
-
canvas
-
- Source:
Properties:
Name Type Description canvasPhaser.Graphics The canvas to render the debug info to.
-
classType
-
The type of objects that will be created when you use Group.create or Group.createMultiple. Defaults to Phaser.Sprite. When a new object is created it is passed the following parameters to its constructor: game, x, y, key, frame.
- Inherited From:
- Source:
Properties:
Name Type Description classTypeobject -
cursor
-
The cursor is a simple way to iterate through the objects in a Group using the Group.next and Group.previous functions. The cursor is set to the first child added to the Group and doesn't change unless you call next, previous or set it directly with Group.cursor.
- Inherited From:
- Source:
Properties:
Name Type Description cursorany The current display object that the Group cursor is pointing to.
-
enableBody
-
- Inherited From:
- Default Value:
- enableBody
- Source:
Properties:
Name Type Description enableBodyboolean If true all Sprites created by, or added to this Group, will have a physics body enabled on them. Change the body type with
Group.physicsBodyType. -
enableBodyDebug
-
- Inherited From:
- Source:
Properties:
Name Type Description enableBodyDebugboolean If true when a physics body is created (via Group.enableBody) it will create a physics debug object as well. Only works for P2 bodies.
-
exists
-
- Inherited From:
- Default Value:
- true
- Source:
Properties:
Name Type Description existsboolean If exists is true the Group is updated, otherwise it is skipped.
-
fixedToCamera
-
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
- Inherited From:
- Source:
Properties:
Name Type Description fixedToCameraboolean Set to true to fix this Group to the Camera at its current world coordinates.
-
game
-
- Inherited From:
- Source:
Properties:
Name Type Description gamePhaser.Game A reference to the currently running Game.
-
<readonly> length
-
- Inherited From:
- Source:
Properties:
Name Type Description lengthnumber The total number of children in this Group, regardless of their exists/alive status.
-
name
-
- Inherited From:
- Source:
Properties:
Name Type Description namestring A name for this Group. Not used internally but useful for debugging.
-
onDestroy
-
- Inherited From:
- Source:
Properties:
Name Type Description onDestroyPhaser.Signal This signal is dispatched when the parent is destoyed.
-
physicsBodyType
-
- Inherited From:
- Source:
Properties:
Name Type Description physicsBodyTypenumber If Group.enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc.
-
ppu
-
- Source:
Properties:
Name Type Description ppunumber Pixels per Length Unit.
-
rotation
-
The angle of rotation of the Group container. This will adjust the Group container itself by modifying its rotation. This will have no impact on the rotation value of its children, but it will update their worldTransform and on-screen position.
- Inherited From:
- Source:
Properties:
Name Type Description rotationnumber The angle of rotation given in radians.
-
scale
-
- Inherited From:
- Source:
Properties:
Name Type Description scalePhaser.Point The scale of the Group container.
-
<readonly> total
-
- Inherited From:
- Source:
Properties:
Name Type Description totalnumber The total number of children in this Group who have a state of exists = true.
-
<protected> type
-
- Inherited From:
- Source:
Properties:
Name Type Description typenumber Internal Phaser Type value.
-
visible
-
- Inherited From:
- Source:
Properties:
Name Type Description visibleboolean The visible state of the Group. Non-visible Groups and all of their children are not rendered.
-
x
-
The x coordinate of the Group container. You can adjust the Group container itself by modifying its coordinates. This will have no impact on the x/y coordinates of its children, but it will update their worldTransform and on-screen position.
- Inherited From:
- Source:
Properties:
Name Type Description xnumber The x coordinate of the Group container.
-
y
-
The y coordinate of the Group container. You can adjust the Group container itself by modifying its coordinates. This will have no impact on the x/y coordinates of its children, but it will update their worldTransform and on-screen position.
- Inherited From:
- Source:
Properties:
Name Type Description ynumber The y coordinate of the Group container.
-
z
-
- Inherited From:
- Source:
Properties:
Name Type Description znumber The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
Methods
-
add(child, silent) → {*}
-
Adds an existing object to this Group. The object can be an instance of Phaser.Sprite, Phaser.Button or any other display object. The child is automatically added to the top of the Group, so renders on-top of everything else within the Group. If you need to control that then see the addAt method.
Parameters:
Name Type Argument Default Description child* An instance of Phaser.Sprite, Phaser.Button or any other display object.
silentboolean <optional>
false If the silent parameter is
truethe child will not dispatch the onAddedToGroup event.- Inherited From:
- Source:
- See:
Returns:
The child that was added to the Group.
- Type
- *
-
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 propertystring The property to increment, for example 'body.velocity.x' or 'angle'.
amountnumber The amount to increment the property by. If child.x = 10 then addAll('x', 40) would make child.x = 50.
checkAliveboolean If true the property will only be changed if the child is alive.
checkVisibleboolean If true the property will only be changed if the child is visible.
- Inherited From:
- Source:
-
addAt(child, index, silent) → {*}
-
Adds an existing object to this Group. The object can be an instance of Phaser.Sprite, Phaser.Button or any other display object. The child is added to the Group at the location specified by the index value, this allows you to control child ordering.
Parameters:
Name Type Argument Default Description child* An instance of Phaser.Sprite, Phaser.Button or any other display object..
indexnumber The index within the Group to insert the child to.
silentboolean <optional>
false If the silent parameter is
truethe child will not dispatch the onAddedToGroup event.- Inherited From:
- Source:
Returns:
The child that was added to the Group.
- Type
- *
-
addMultiple(children, silent) → {*}
-
Adds an array existing objects to this Group. The objects can be instances of Phaser.Sprite, Phaser.Button or any other display object. The children are automatically added to the top of the Group, so render on-top of everything else within the Group. TODO: Add ability to pass the children as parameters rather than having to be an array.
Parameters:
Name Type Argument Default Description childrenarray An array containing instances of Phaser.Sprite, Phaser.Button or any other display object.
silentboolean <optional>
false If the silent parameter is
truethe children will not dispatch the onAddedToGroup event.- Inherited From:
- Source:
Returns:
The array of children that were added to the Group.
- Type
- *
-
ascendingSortHandler(a, b)
-
An internal helper function for the sort process.
Parameters:
Name Type Description aobject The first object being sorted.
bobject The second object being sorted.
- Inherited From:
- Source:
-
bringToTop(child) → {*}
-
Brings the given child to the top of this Group so it renders above all other children.
Parameters:
Name Type Description child* The child to bring to the top of this Group.
- Inherited From:
- Source:
Returns:
The child that was moved.
- Type
- *
-
callAll(method, context, 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 method parameter and context you can add as many extra parameters as you like, which will all be passed to the child.
Parameters:
Name Type Argument Default Description methodstring A string containing the name of the function that will be called. The function must exist on the child.
contextstring <optional>
null A string containing the context under which the method will be executed. Set to null to default to the child.
parameter* <repeatable>
Additional parameters that will be passed to the method.
- Inherited From:
- Source:
-
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 callbackfunction The function that exists on the children that will be called.
existsValueboolean Only children with exists=existsValue will be called.
parameter* <repeatable>
Additional parameters that will be passed to the callback.
- Inherited From:
- Source:
-
<protected> callbackFromArray(child, callback, length)
-
Returns a reference to a function that exists on a child of the Group based on the given callback array.
Parameters:
Name Type Description childobject The object to inspect.
callbackarray The array of function names.
lengthnumber The size of the array (pre-calculated in callAll).
- Inherited From:
- Source:
-
checkAll(key, value, checkAlive, checkVisible, force)
-
This function allows you to quickly check that the same property across all children of this Group is equal to the given value. This call doesn't descend down children, so if you have a Group inside of this Group, the property will be checked on the Group but not its children.
Parameters:
Name Type Argument Default Description keystring The property, as a string, to be set. For example: 'body.velocity.x'
value* The value that will be checked.
checkAliveboolean <optional>
false If set then only children with alive=true will be checked. This includes any Groups that are children.
checkVisibleboolean <optional>
false If set then only children with visible=true will be checked. This includes any Groups that are children.
forceboolean <optional>
false If
forceis true then the property will be checked on the child regardless if it already exists or not. If true and the property doesn't exist, false will be returned.- Inherited From:
- Source:
-
checkProperty(child, key, value, force) → {boolean}
-
Checks a property for the given value on the child.
Parameters:
Name Type Argument Default Description child* The child to check the property value on.
keyarray An array of strings that make up the property that will be set.
value* The value that will be checked.
forceboolean <optional>
false If
forceis true then the property will be checked on the child regardless if it already exists or not. If true and the property doesn't exist, false will be returned.- Inherited From:
- Source:
Returns:
True if the property was was equal to value, false if not.
- Type
- boolean
-
componentToHex()
-
Component to hex conversion.
- Source:
-
countDead() → {number}
-
Call this function to find out how many members of the group are dead.
- Inherited From:
- Source:
Returns:
The number of children flagged as dead.
- Type
- number
-
countLiving() → {number}
-
Call this function to find out how many members of the group are alive.
- Inherited From:
- Source:
Returns:
The number of children flagged as alive.
- Type
- number
-
create(x, y, key, frame, exists) → {Phaser.Sprite|object}
-
Automatically creates a new Phaser.Sprite object and adds it to the top of this Group. You can change Group.classType to any object and this call will create an object of that type instead, but it should extend either Sprite or Image.
Parameters:
Name Type Argument Default Description xnumber The x coordinate to display the newly created Sprite at. The value is in relation to the Group.x point.
ynumber The y coordinate to display the newly created Sprite at. The value is in relation to the Group.y point.
keystring The Game.cache key of the image that this Sprite will use.
framenumber | string <optional>
If the Sprite image contains multiple frames you can specify which one to use here.
existsboolean <optional>
true The default exists state of the Sprite.
- Inherited From:
- Source:
Returns:
The child that was created. Will be a Phaser.Sprite unless Group.classType has been changed.
- Type
- Phaser.Sprite | object
-
createMultiple(quantity, key, frame, exists)
-
Automatically creates multiple Phaser.Sprite objects and adds them to the top of this Group. Useful if you need to quickly generate a pool of identical sprites, such as bullets. By default the sprites will be set to not exist and will be positioned at 0, 0 (relative to the Group.x/y) You can change Group.classType to any object and this call will create an object of that type instead, but it should extend either Sprite or Image.
Parameters:
Name Type Argument Default Description quantitynumber The number of Sprites to create.
keystring The Game.cache key of the image that this Sprite will use.
framenumber | string <optional>
If the Sprite image contains multiple frames you can specify which one to use here.
existsboolean <optional>
false The default exists state of the Sprite.
- Inherited From:
- Source:
-
customSort(sortHandler, context)
-
This allows you to use your own sort handler function. It will be sent two parameters: the two children involved in the comparison (a and b). It should return -1 if a > b, 1 if a < b or 0 if a === b.
Parameters:
Name Type Description sortHandlerfunction Your sort handler function. It will be sent two parameters: the two children involved in the comparison. It must return -1, 1 or 0.
contextobject The scope in which the sortHandler is called.
- Inherited From:
- Source:
-
descendingSortHandler(a, b)
-
An internal helper function for the sort process.
Parameters:
Name Type Description aobject The first object being sorted.
bobject The second object being sorted.
- Inherited From:
- Source:
-
destroy(destroyChildren, soft)
-
Destroys this Group. Removes all children, then removes the container from the display list and nulls references.
Parameters:
Name Type Argument Default Description destroyChildrenboolean <optional>
true Should every child of this Group have its destroy method called?
softboolean <optional>
false A 'soft destroy' (set to true) doesn't remove this Group from its parent or null the game reference. Set to false and it does.
- Inherited From:
- Source:
-
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 propertystring The property to divide, for example 'body.velocity.x' or 'angle'.
amountnumber The amount to divide the property by. If child.x = 100 then divideAll('x', 2) would make child.x = 50.
checkAliveboolean If true the property will only be changed if the child is alive.
checkVisibleboolean If true the property will only be changed if the child is visible.
- Inherited From:
- Source:
-
draw()
-
Draws the P2 shapes to the Graphics object.
- Source:
-
draw()
-
Draws the P2 shapes to the Graphics object.
- Source:
-
drawCircle()
-
Draws a P2 Circle shape.
- Source:
-
drawCircle()
-
Draws a P2 Line shape.
- Source:
-
drawConvex()
-
Draws a P2 Convex shape.
- Source:
-
drawPath()
-
Draws a P2 Path.
- Source:
-
drawPlane()
-
Draws a P2 Plane shape.
- Source:
-
forEach(callback, callbackContext, checkExists)
-
Allows you to call your own function on each member of this Group. You must pass the callback and context in which it will run. 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. For example: Group.forEach(awardBonusGold, this, true, 100, 500) Note: Currently this will skip any children which are Groups themselves.
Parameters:
Name Type Argument Default Description callbackfunction The function that will be called. Each child of the Group will be passed to it as its first parameter.
callbackContextObject The context in which the function should be called (usually 'this').
checkExistsboolean <optional>
false If set only children with exists=true will be passed to the callback, otherwise all children will be passed.
- Inherited From:
- Source:
-
forEachAlive(callback, callbackContext)
-
Allows you to call your own function on each alive member of this Group (where child.alive=true). You must pass the callback and context in which it will run. You can add as many parameters as you like, which will all be passed to the callback along with the child. For example: Group.forEachAlive(causeDamage, this, 500)
Parameters:
Name Type Description callbackfunction The function that will be called. Each child of the Group will be passed to it as its first parameter.
callbackContextObject The context in which the function should be called (usually 'this').
- Inherited From:
- Source:
-
forEachDead(callback, callbackContext)
-
Allows you to call your own function on each dead member of this Group (where alive=false). You must pass the callback and context in which it will run. You can add as many parameters as you like, which will all be passed to the callback along with the child. For example: Group.forEachDead(bringToLife, this)
Parameters:
Name Type Description callbackfunction The function that will be called. Each child of the Group will be passed to it as its first parameter.
callbackContextObject The context in which the function should be called (usually 'this').
- Inherited From:
- Source:
-
forEachExists(callback, callbackContext)
-
Allows you to call your own function on each member of this Group where child.exists=true. You must pass the callback and context in which it will run. You can add as many parameters as you like, which will all be passed to the callback along with the child. For example: Group.forEachExists(causeDamage, this, 500)
Parameters:
Name Type Description callbackfunction The function that will be called. Each child of the Group will be passed to it as its first parameter.
callbackContextObject The context in which the function should be called (usually 'this').
- Inherited From:
- Source:
-
getAt(index) → {*}
-
Returns the child found at the given index within this Group.
Parameters:
Name Type Description indexnumber The index to return the child from.
- Inherited From:
- Source:
Returns:
The child that was found at the given index. If the index was out of bounds then this will return -1.
- Type
- *
-
getBottom() → {Any}
-
Returns the child at the bottom of this Group. The bottom is the one being displayed (rendered) below every other child.
- Inherited From:
- Source:
Returns:
The child at the bottom of the Group.
- Type
- Any
-
getFirstAlive() → {Any}
-
Call this function to retrieve the first object with alive === true in the group. This is handy for checking if everything has been wiped out, or choosing a squad leader, etc.
- Inherited From:
- Source:
Returns:
The first alive child, or null if none found.
- Type
- Any
-
getFirstDead() → {Any}
-
Call this function to retrieve the first object with alive === false in the group. This is handy for checking if everything has been wiped out, or choosing a squad leader, etc.
- Inherited From:
- Source:
Returns:
The first dead child, or null if none found.
- Type
- Any
-
getFirstExists(state) → {Any}
-
Call this function to retrieve the first object with exists == (the given state) in the Group.
Parameters:
Name Type Description stateboolean True or false.
- Inherited From:
- Source:
Returns:
The first child, or null if none found.
- Type
- Any
-
getIndex(child) → {number}
-
Get the index position of the given child in this Group. This should always match the childs z property.
Parameters:
Name Type Description child* The child to get the index for.
- Inherited From:
- Source:
Returns:
The index of the child or -1 if it's not a member of this Group.
- Type
- number
-
getRandom(startIndex, length) → {Any}
-
Returns a member at random from the group.
Parameters:
Name Type Description startIndexnumber Optional offset off the front of the array. Default value is 0, or the beginning of the array.
lengthnumber Optional restriction on the number of values you want to randomly select from.
- Inherited From:
- Source:
Returns:
A random child of this Group.
- Type
- Any
-
getTop() → {Any}
-
Returns the child at the top of this Group. The top is the one being displayed (rendered) above every other child.
- Inherited From:
- Source:
Returns:
The child at the top of the Group.
- Type
- Any
-
hasProperty(child, key) → {boolean}
-
Checks if the child has the given property. Will scan up to 4 levels deep only.
Parameters:
Name Type Description child* The child to check for the existance of the property on.
keyarray An array of strings that make up the property.
- Inherited From:
- Source:
Returns:
True if the child has the property, otherwise false.
- Type
- boolean
-
iterate(key, value, returnType, callback, callbackContext) → {any}
-
Iterates over the children of the Group. When a child has a property matching key that equals the given value, it is considered as a match. Matched children can be sent to the optional callback, or simply returned or counted. You can add as many callback parameters as you like, which will all be passed to the callback along with the child, after the callbackContext parameter.
Parameters:
Name Type Argument Default Description keystring The child property to check, i.e. 'exists', 'alive', 'health'
valueany If child.key === this value it will be considered a match. Note that a strict comparison is used.
returnTypenumber How to return the data from this method. Either Phaser.Group.RETURN_NONE, Phaser.Group.RETURN_TOTAL or Phaser.Group.RETURN_CHILD.
callbackfunction <optional>
null Optional function that will be called on each matching child. Each child of the Group will be passed to it as its first parameter.
callbackContextObject <optional>
The context in which the function should be called (usually 'this').
- Inherited From:
- Source:
Returns:
Returns either a numeric total (if RETURN_TOTAL was specified) or the child object.
- Type
- any
-
moveDown(child) → {*}
-
Moves the given child down one place in this Group unless it's already at the top.
Parameters:
Name Type Description child* The child to move down in the Group.
- Inherited From:
- Source:
Returns:
The child that was moved.
- Type
- *
-
moveUp(child) → {*}
-
Moves the given child up one place in this Group unless it's already at the top.
Parameters:
Name Type Description child* The child to move up in the Group.
- Inherited From:
- Source:
Returns:
The child that was moved.
- Type
- *
-
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 propertystring The property to multiply, for example 'body.velocity.x' or 'angle'.
amountnumber The amount to multiply the property by. If child.x = 10 then multiplyAll('x', 2) would make child.x = 20.
checkAliveboolean If true the property will only be changed if the child is alive.
checkVisibleboolean If true the property will only be changed if the child is visible.
- Inherited From:
- Source:
-
next() → {*}
-
Advances the Group cursor to the next object in the Group. If it's at the end of the Group it wraps around to the first object.
- Inherited From:
- Source:
Returns:
The child the cursor now points to.
- Type
- *
-
<protected> postUpdate()
-
The core postUpdate - as called by World.
- Inherited From:
- Source:
-
<protected> preUpdate()
-
The core preUpdate - as called by World.
- Inherited From:
- Source:
-
previous() → {*}
-
Moves the Group cursor to the previous object in the Group. If it's at the start of the Group it wraps around to the last object.
- Inherited From:
- Source:
Returns:
The child the cursor now points to.
- Type
- *
-
randomPastelHex()
-
Picks a random pastel color.
- Source:
-
remove(child, destroy, silent) → {boolean}
-
Removes the given child from this Group. This will dispatch an onRemovedFromGroup event from the child (if it has one), reset the Group cursor and optionally destroy the child.
Parameters:
Name Type Argument Default Description childAny The child to remove.
destroyboolean <optional>
false You can optionally call destroy on the child that was removed.
silentboolean <optional>
false If the silent parameter is
truethe child will not dispatch the onRemovedFromGroup event.- Inherited From:
- Source:
Returns:
true if the child was removed from this Group, otherwise false.
- Type
- boolean
-
removeAll(destroy, silent)
-
Removes all children from this Group, setting the group properties of the children to
null. The Group container remains on the display list.Parameters:
Name Type Argument Default Description destroyboolean <optional>
false You can optionally call destroy on each child that is removed.
silentboolean <optional>
false If the silent parameter is
truethe children will not dispatch their onRemovedFromGroup events.- Inherited From:
- Source:
-
removeBetween(startIndex, endIndex, destroy, silent)
-
Removes all children from this Group whos index falls beteen the given startIndex and endIndex values.
Parameters:
Name Type Argument Default Description startIndexnumber The index to start removing children from.
endIndexnumber <optional>
The index to stop removing children at. Must be higher than startIndex. If undefined this method will remove all children between startIndex and the end of the Group.
destroyboolean <optional>
false You can optionally call destroy on the child that was removed.
silentboolean <optional>
false If the silent parameter is
truethe children will not dispatch their onRemovedFromGroup events.- Inherited From:
- Source:
-
replace(oldChild, newChild) → {*}
-
Replaces a child of this Group with the given newChild. The newChild cannot be a member of this Group.
Parameters:
Name Type Description oldChild* The child in this Group that will be replaced.
newChild* The child to be inserted into this Group.
- Inherited From:
- Source:
Returns:
Returns the oldChild that was replaced within this Group.
- Type
- *
-
resetCursor(index) → {*}
-
Sets the Group cursor to the first object in the Group. If the optional index parameter is given it sets the cursor to the object at that index instead.
Parameters:
Name Type Argument Default Description indexnumber <optional>
0 Set the cursor to point to a specific index.
- Inherited From:
- Source:
Returns:
The child the cursor now points to.
- Type
- *
-
reverse()
-
Reverses all children in this Group. Note that this does not propagate, only direct children are re-ordered.
- Inherited From:
- Source:
-
rgbToHex()
-
Converts from RGB to Hex.
- Source:
-
sendToBack(child) → {*}
-
Sends the given child to the bottom of this Group so it renders below all other children.
Parameters:
Name Type Description child* The child to send to the bottom of this Group.
- Inherited From:
- Source:
Returns:
The child that was moved.
- Type
- *
-
set(child, key, value, checkAlive, checkVisible, operation, force) → {boolean}
-
This function allows you to quickly set a property on a single child of this Group to a new value. The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
Parameters:
Name Type Argument Default Description childPhaser.Sprite The child to set the property on.
keystring The property, as a string, to be set. For example: 'body.velocity.x'
value* The value that will be set.
checkAliveboolean <optional>
false If set then the child will only be updated if alive=true.
checkVisibleboolean <optional>
false If set then the child will only be updated if visible=true.
operationnumber <optional>
0 Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
forceboolean <optional>
false If
forceis true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set.- Inherited From:
- Source:
Returns:
True if the property was set, false if not.
- Type
- boolean
-
setAll(key, value, checkAlive, checkVisible, operation, force)
-
This function allows you to quickly set the same property across all children of this Group to a new value. This call doesn't descend down children, so if you have a Group inside of this Group, the property will be set on the Group but not its children. If you need that ability please see
Group.setAllChildren.The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
Parameters:
Name Type Argument Default Description keystring The property, as a string, to be set. For example: 'body.velocity.x'
value* The value that will be set.
checkAliveboolean <optional>
false If set then only children with alive=true will be updated. This includes any Groups that are children.
checkVisibleboolean <optional>
false If set then only children with visible=true will be updated. This includes any Groups that are children.
operationnumber <optional>
0 Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
forceboolean <optional>
false If
forceis true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set.- Inherited From:
- Source:
-
setAllChildren(key, value, checkAlive, checkVisible, operation, force)
-
This function allows you to quickly set the same property across all children of this Group, and any child Groups, to a new value.
If this Group contains other Groups then the same property is set across their children as well, iterating down until it reaches the bottom. Unlike with Group.setAll the property is NOT set on child Groups itself.
The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
Parameters:
Name Type Argument Default Description keystring The property, as a string, to be set. For example: 'body.velocity.x'
value* The value that will be set.
checkAliveboolean <optional>
false If set then only children with alive=true will be updated. This includes any Groups that are children.
checkVisibleboolean <optional>
false If set then only children with visible=true will be updated. This includes any Groups that are children.
operationnumber <optional>
0 Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
forceboolean <optional>
false If
forceis true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set.- Inherited From:
- Source:
-
setProperty(child, key, value, operation, force) → {boolean}
-
Sets a property to the given value on the child. The operation parameter controls how the value is set. Operation 0 means set the existing value to the given value, or if force is
falsecreate a new property with the given value. 1 will add the given value to the value already present. 2 will subtract the given value from the value already present. 3 will multiply the value already present by the given value. 4 will divide the value already present by the given value.Parameters:
Name Type Argument Default Description child* The child to set the property value on.
keyarray An array of strings that make up the property that will be set.
value* The value that will be set.
operationnumber <optional>
0 Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
forceboolean <optional>
false If
forceis true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set.- Inherited From:
- Source:
Returns:
True if the property was set, false if not.
- Type
- boolean
-
sort(index, order)
-
Call this function to sort the group according to a particular 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 yourState.update().Parameters:
Name Type Argument Default Description indexstring <optional>
'z' The
stringname of the property you want to sort on. Defaults to the objects z-depth value.ordernumber <optional>
Phaser.Group.SORT_ASCENDING The
Groupconstant that defines the sort order. Possible values are Phaser.Group.SORT_ASCENDING and Phaser.Group.SORT_DESCENDING.- Inherited From:
- Source:
-
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 propertystring The property to decrement, for example 'body.velocity.x' or 'angle'.
amountnumber The amount to subtract from the property. If child.x = 50 then subAll('x', 40) would make child.x = 10.
checkAliveboolean If true the property will only be changed if the child is alive.
checkVisibleboolean If true the property will only be changed if the child is visible.
- Inherited From:
- Source:
-
swap(child1, child2)
-
Swaps the position of two children in this Group. Both children must be in this Group. You cannot swap a child with itself, or swap un-parented children.
Parameters:
Name Type Description child1* The first child to swap.
child2* The second child to swap.
- Inherited From:
- Source:
-
update()
-
Core update.
- Source:
-
updateSpriteTransform()
-
Core update.
- Source:
-
<protected> updateZ()
-
Internal method that re-applies all of the childrens Z values.
- Inherited From:
- Source:
-
xy(index, x, y)
-
Positions the child found at the given index within this Group to the given x and y coordinates.
Parameters:
Name Type Description indexnumber The index of the child in the Group to set the position of.
xnumber The new x position of the child.
ynumber The new y position of the child.
- Inherited From:
- Source: