new World(game)
"This world is but a canvas to our imagination." - Henry David Thoreau
A game has only one world. The world is an abstract place in which all game objects live. It is not bound by stage limits and can be any size. You look into the world via cameras. All game objects live within the world at world-based coordinates. By default a world is created the same size as your Stage.
Parameters:
| Name | Type | Description |
|---|---|---|
game |
Phaser.Game | Reference to the current game instance. |
- Source:
- src/core/World.js line 19
Extends
Members
-
<readonly> _definedSize : boolean
-
True if the World has been given a specifically defined size (i.e. from a Tilemap or direct in code) or false if it's just matched to the Game dimensions.
Type:
- boolean
- Source:
- src/core/World.js line 41
-
_height
-
- Source:
- src/core/World.js line 51
Properties:
Name Type Description heightnumber The defined height of the World. Sometimes the bounds needs to grow larger than this (if you resize the game) but this retains the original requested dimension.
-
_width
-
- Source:
- src/core/World.js line 46
Properties:
Name Type Description widthnumber The defined width of the World. Sometimes the bounds needs to grow larger than this (if you resize the game) but this retains the original requested dimension.
-
alive : boolean
-
The alive property is useful for Groups that are children of other Groups and need to be included/excluded in checks like forEachAlive.
Type:
- boolean
- Inherited From:
- Default Value:
-
- true
- Source:
- src/core/Group.js line 93
-
alpha : number
-
The alpha value of the group container.
Type:
- number
- Inherited From:
- Source:
- src/core/Group.js line 3167
-
angle : number
-
The angle of rotation of the group container, in degrees.
This adjusts the group itself by modifying its local rotation transform.
This has no impact on the rotation/angle properties of the children, but it will update their worldTransform and on-screen orientation and position.
Type:
- number
- Inherited From:
- Source:
- src/core/Group.js line 2827
-
bottom : number
-
The bottom coordinate of this Group.
It is derived by calling
getBounds, calculating the Groups dimensions based on its visible children.Type:
- number
- Inherited From:
- Source:
- src/core/Group.js line 2990
-
bounds : Phaser.Rectangle
-
The World has no fixed size, but it does have a bounds outside of which objects are no longer considered as being "in world" and you should use this to clean-up the display list and purge dead objects. By default we set the Bounds to be from 0,0 to Game.width,Game.height. I.e. it will match the size given to the game constructor with 0,0 representing the top-left of the display. However 0,0 is actually the center of the world, and if you rotate or scale the world all of that will happen from 0,0. So if you want to make a game in which the world itself will rotate you should adjust the bounds so that 0,0 is the center point, i.e. set them to -1000,-1000,2000,2000 for a 2000x2000 sized world centered around 0,0. Bound of this world that objects can not escape from.
Type:
- Source:
- src/core/World.js line 30
-
cacheAsBitmap : boolean
-
Sets if this DisplayObject should be cached as a bitmap.
When invoked it will take a snapshot of the DisplayObject, as it is at that moment, and store it in a RenderTexture. This is then used whenever this DisplayObject is rendered. It can provide a performance benefit for complex, but static, DisplayObjects. I.e. those with lots of children.
Transparent areas adjoining the edges may be removed (#283).
Cached Bitmaps do not track their parents. If you update a property of this DisplayObject, it will not re-generate the cached bitmap automatically. To do that you need to call
DisplayObject.updateCache.To remove a cached bitmap, set this property to
null. Cache this DisplayObject as a Bitmap. Set tonullto remove an existing cached bitmap.Type:
- boolean
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 794
-
camera : Phaser.Camera
-
Camera instance.
Type:
- Source:
- src/core/World.js line 35
-
cameraOffset : Phaser.Point
-
If this object is fixedToCamera then this stores the x/y position offset relative to the top-left of the camera view. If the parent of this Group is also
fixedToCamerathen the offset here is in addition to that and should typically be disabled.Type:
- Inherited From:
- Source:
- src/core/Group.js line 279
-
<readonly> centerX : number
-
Gets the X position corresponding to the center point of the world.
Type:
- number
- Overrides:
- Source:
- src/core/World.js line 293
-
<readonly> centerY : number
-
Gets the Y position corresponding to the center point of the world.
Type:
- number
- Overrides:
- Source:
- src/core/World.js line 306
-
<readonly> children : Array(DisplayObject)
-
[read-only] The array of children of this container.
Type:
- Array(DisplayObject)
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 24
-
classType : function
-
The type of objects that will be created when using create or createMultiple.
It should extend either Sprite or Image and accept the same constructor arguments:
(game, x, y, key, frame).Type:
- function
- Inherited From:
- Default Value:
- Source:
- src/core/Group.js line 129
-
cursor : DisplayObject
-
The current display object that the group cursor is pointing to, if any. (Can be set manually.)
The cursor is a way to iterate through the children in a Group using next and previous.
Type:
- Inherited From:
- Source:
- src/core/Group.js line 137
-
<readonly> cursorIndex : integer
-
The current index of the Group cursor. Advance it with Group.next.
Type:
- integer
- Inherited From:
- Source:
- src/core/Group.js line 262
-
enableBody : boolean
-
If true all Sprites created by, or added to this group, will have a physics body enabled on them.
If there are children already in the Group at the time you set this property, they are not changed.
The default body type is controlled with physicsBodyType.
Type:
- boolean
- Inherited From:
- Source:
- src/core/Group.js line 215
-
enableBodyDebug : boolean
-
If true when a physics body is created (via enableBody) it will create a physics debug object as well.
This only works for P2 bodies.
Type:
- boolean
- Inherited From:
- Source:
- src/core/Group.js line 224
-
exists : boolean
-
If exists is false the group will be excluded from collision checks and filters such as forEachExists. The group will not call
preUpdateandpostUpdateon its children and the children will not receive physics updates or camera/world boundary checks. The group will still be visible and will still callupdateon its children.Type:
- boolean
- Inherited From:
- Default Value:
-
- true
- Source:
- src/core/Group.js line 100
-
filterArea : Rectangle
-
The rectangular area used by filters when rendering a shader for this DisplayObject.
Type:
- Rectangle
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 202
-
filters : Array
-
Sets the filters for this DisplayObject. This is a WebGL only feature, and is ignored by the Canvas Renderer. A filter is a shader applied to this DisplayObject. You can modify the placement of the filter using
DisplayObject.filterArea.To remove filters, set this property to
null.Note: You cannot have a filter set, and a MULTIPLY Blend Mode active, at the same time. Setting a filter will reset this DisplayObjects blend mode to NORMAL. An Array of Phaser.Filter objects, or objects that extend them.
Type:
- Array
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 741
-
fixedToCamera : boolean
-
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
Type:
- boolean
- Inherited From:
- Source:
- src/core/Group.js line 272
-
<protected> game : Phaser.Game
-
A reference to the currently running Game.
Type:
- Inherited From:
- Source:
- src/core/Group.js line 38
-
hash : array
-
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)
Type:
- array
- Inherited From:
- Source:
- src/core/Group.js line 292
-
height : number
-
Gets or sets the current height of the game world. The world can never be smaller than the game (canvas) dimensions.
Type:
- number
- Source:
- src/core/World.js line 268
-
hitArea : Rectangle | Circle | Ellipse | Polygon
-
This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)
Type:
- Rectangle | Circle | Ellipse | Polygon
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 96
-
ignoreChildInput : boolean
-
If
ignoreChildInputisfalseit will allow this objects children to be considered as valid for Input events.If this property is
truethen the children will not be considered as valid for Input events.Note that this property isn't recursive: only immediate children are influenced, it doesn't scan further down.
Type:
- boolean
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 35
-
ignoreDestroy : boolean
-
A group with
ignoreDestroyset totrueignores all calls to itsdestroymethod.Type:
- boolean
- Inherited From:
- Source:
- src/core/Group.js line 107
-
inputEnableChildren : boolean
-
A Group with
inputEnableChildrenset totruewill automatically callinputEnabled = trueon 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.
Type:
- boolean
- Inherited From:
- Source:
- src/core/Group.js line 148
-
left : number
-
The left coordinate of this Group.
It is derived by calling
getBounds, calculating the Groups dimensions based on its visible children.Type:
- number
- Inherited From:
- Source:
- src/core/Group.js line 2906
-
<readonly> length : integer
-
Total number of children in this group, regardless of exists/alive status.
Type:
- integer
- Inherited From:
- Source:
- src/core/Group.js line 2810
-
mask : Phaser.Graphics
-
Sets a mask for this DisplayObject. A mask is an instance of a Graphics object. When applied it limits the visible area of this DisplayObject to the shape of the mask. Under a Canvas renderer it uses shape clipping. Under a WebGL renderer it uses a Stencil Buffer. To remove a mask, set this property to
null. The mask applied to this DisplayObject. Set tonullto remove an existing mask.Type:
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 706
-
name : string
-
A name for this group. Not used internally but useful for debugging.
Type:
- string
- Inherited From:
- Source:
- src/core/Group.js line 49
-
onChildInputDown : Phaser.Signal
-
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.
Type:
- Inherited From:
- Source:
- src/core/Group.js line 168
-
onChildInputOut : Phaser.Signal
-
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.
Type:
- Inherited From:
- Source:
- src/core/Group.js line 205
-
onChildInputOver : Phaser.Signal
-
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.
Type:
- Inherited From:
- Source:
- src/core/Group.js line 193
-
onChildInputUp : Phaser.Signal
-
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, a reference to the Pointer that caused it, and a boolean value
isOverthat tells you if the Pointer is still over the Sprite or not.Type:
- Inherited From:
- Source:
- src/core/Group.js line 181
-
onDestroy : Phaser.Signal
-
This signal is dispatched when the group is destroyed.
Type:
- Inherited From:
- Source:
- src/core/Group.js line 256
-
<readonly> parent : PIXI.DisplayObjectContainer
-
The parent DisplayObjectContainer that this DisplayObject is a child of. All DisplayObjects must belong to a parent in order to be rendered. The root parent is the Stage object. This property is set automatically when the DisplayObject is added to, or removed from, a DisplayObjectContainer.
Type:
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 117
-
pendingDestroy : boolean
-
A Group is that has
pendingDestroyset totrueis flagged to have its destroy method called on the next logic update. You can set it directly to flag the Group to be destroyed on its next update.This is extremely useful if you wish to destroy a Group from within one of its own callbacks or a callback of one of its children.
Type:
- boolean
- Inherited From:
- Source:
- src/core/Group.js line 119
-
physicsBodyType : integer
-
If enableBody is true this is the type of physics body that is created on new Sprites.
The valid values are Phaser.Physics.ARCADE, Phaser.Physics.P2JS, Phaser.Physics.NINJA, etc.
Type:
- integer
- Inherited From:
- Source:
- src/core/Group.js line 232
-
physicsSortDirection : integer
-
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:
Phaser.Physics.Arcade.SORT_NONE Phaser.Physics.Arcade.LEFT_RIGHT Phaser.Physics.Arcade.RIGHT_LEFT Phaser.Physics.Arcade.TOP_BOTTOM Phaser.Physics.Arcade.BOTTOM_TOP
If set to
nullthe Group will use whatever Phaser.Physics.Arcade.sortDirection is set to. This is the default behavior.Type:
- integer
- Inherited From:
- Source:
- src/core/Group.js line 250
-
<readonly> physicsType : number
-
The const physics body type of this object.
Type:
- number
- Inherited From:
- Source:
- src/core/Group.js line 86
-
pivot : PIXI.Point
-
The pivot point of this DisplayObject that it rotates around. The values are expressed in pixel values.
Type:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 49
-
position : PIXI.Point
-
The coordinates, in pixels, of this DisplayObject, relative to its parent container.
The value of this property does not reflect any positioning happening further up the display list. To obtain that value please see the
worldPositionproperty.Type:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 29
-
<readonly> randomX : number
-
Gets a random integer which is lesser than or equal to the current width of the game world.
Type:
- number
- Source:
- src/core/World.js line 319
-
<readonly> randomY : number
-
Gets a random integer which is lesser than or equal to the current height of the game world.
Type:
- number
- Source:
- src/core/World.js line 341
-
renderable : boolean
-
Should this DisplayObject be rendered by the renderer? An object with a renderable value of
falseis skipped during the render pass.Type:
- boolean
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 105
-
right : number
-
The right coordinate of this Group.
It is derived by calling
getBounds, calculating the Groups dimensions based on its visible children.Type:
- number
- Inherited From:
- Source:
- src/core/Group.js line 2934
-
rotation : number
-
The angle of rotation of the group container, in radians.
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.
Type:
- number
- Inherited From:
- Source:
- src/core/Group.js line 3151
-
scale : PIXI.Point
-
The scale of this DisplayObject. A scale of 1:1 represents the DisplayObject at its default size. A value of 0.5 would scale this DisplayObject by half, and so on.
The value of this property does not reflect any scaling happening further up the display list. To obtain that value please see the
worldScaleproperty.Type:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 41
-
top : number
-
The top coordinate of this Group.
It is derived by calling
getBounds, calculating the Groups dimensions based on its visible children.Type:
- number
- Inherited From:
- Source:
- src/core/Group.js line 2962
-
<readonly> total : integer
-
Total number of existing children in the group.
Type:
- integer
- Inherited From:
- Source:
- src/core/Group.js line 2793
-
<protected> type : integer
-
Internal Phaser Type value.
Type:
- integer
- Inherited From:
- Source:
- src/core/Group.js line 80
-
updateOnlyExistingChildren : boolean
-
Skip children with
exists = falsein update.Type:
- boolean
- Inherited From:
- Source:
- src/core/Group.js line 156
-
visible : boolean
-
The visible state of the group. Non-visible Groups and all of their children are not rendered.
Type:
- boolean
- Inherited From:
- Source:
- src/core/Group.js line 3160
-
width : number
-
Gets or sets the current width of the game world. The world can never be smaller than the game (canvas) dimensions.
Type:
- number
- Source:
- src/core/World.js line 243
-
<readonly> worldAlpha : number
-
The multiplied alpha value of this DisplayObject. A value of 1 is fully opaque. A value of 0 is transparent. This value is the calculated total, based on the alpha values of all parents of this DisplayObjects in the display list.
To obtain, and set, the local alpha value, see the
alphaproperty.Note: This property is only updated at the end of the
updateTransformcall, once per render. Until that happens this property will contain values based on the previous frame. Be mindful of this if accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.Type:
- number
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 133
-
<readonly> worldPosition : PIXI.Point
-
The coordinates, in pixels, of this DisplayObject within the world.
This property contains the calculated total, based on the positions of all parents of this DisplayObject in the display list.
Note: This property is only updated at the end of the
updateTransformcall, once per render. Until that happens this property will contain values based on the previous frame. Be mindful of this if accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.Type:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 163
-
<readonly> worldRotation : number
-
The rotation, in radians, of this DisplayObject.
This property contains the calculated total, based on the rotations of all parents of this DisplayObject in the display list.
Note: This property is only updated at the end of the
updateTransformcall, once per render. Until that happens this property will contain values based on the previous frame. Be mindful of this if accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.Type:
- number
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 193
-
<readonly> worldScale : PIXI.Point
-
The global scale of this DisplayObject.
This property contains the calculated total, based on the scales of all parents of this DisplayObject in the display list.
Note: This property is only updated at the end of the
updateTransformcall, once per render. Until that happens this property will contain values based on the previous frame. Be mindful of this if accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.Type:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 178
-
<readonly> worldTransform : Phaser.Matrix
-
The current transform of this DisplayObject.
This property contains the calculated total, based on the transforms of all parents of this DisplayObject in the display list.
Note: This property is only updated at the end of the
updateTransformcall, once per render. Until that happens this property will contain values based on the previous frame. Be mindful of this if accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.Type:
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 148
-
worldVisible : boolean
-
Indicates if this DisplayObject is visible, based on it, and all of its parents,
visibleproperty values.Type:
- boolean
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 663
-
x : number
-
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.
Type:
- number
- Inherited From:
- Overrides:
- Source:
- src/core/Group.js line 3133
-
y : number
-
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.
Type:
- number
- Inherited From:
- Overrides:
- Source:
- src/core/Group.js line 3142
-
<readonly> z : integer
-
The z-depth value of this object within its parent container/Group - the World is a Group as well. This value must be unique for each child in a Group.
Type:
- integer
- Inherited From:
- Source:
- src/core/Group.js line 57
Methods
-
add(child [, silent] [, index])
-
Adds an existing object as the top child in this group.
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, 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.
If
Group.enableBodyis set, then a physics body will be created on the object, so long as one does not already exist.If
Group.inputEnableChildrenis set, then an Input Handler will be created on the object, so long as one does not already exist.Use addAt to control where a child is added. Use create to create and add a new child.
Parameters:
Name Type Argument Default Description childDisplayObject The display object to add as a child.
silentboolean <optional>
false If true the child will not dispatch the
onAddedToGroupevent.indexinteger <optional>
The index within the group to insert the child to. Where 0 is the bottom of the Group.
- Inherited From:
- Source:
- src/core/Group.js line 348
Returns:
The child that was added to the group.
- Type
- DisplayObject
-
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 for each child.Parameters:
Name Type Argument 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 <optional>
If true the property will only be changed if the child is alive.
checkVisibleboolean <optional>
If true the property will only be changed if the child is visible.
- Inherited From:
- Source:
- src/core/Group.js line 1431
-
addAt(child [, index] [, silent])
-
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.enableBodyis set, then a physics body will be created on the object, so long as one does not already exist.If
Group.inputEnableChildrenis set, then an Input Handler will be created on the object, so long as one does not already exist.Parameters:
Name Type Argument Default Description childDisplayObject The display object to add as a child.
indexinteger <optional>
0 The index within the group to insert the child to.
silentboolean <optional>
false If true the child will not dispatch the
onAddedToGroupevent.- Inherited From:
- Source:
- src/core/Group.js line 425
Returns:
The child that was added to the group.
- Type
- DisplayObject
-
addChild(child)
-
Adds a child to the container.
Parameters:
Name Type Description childDisplayObject The DisplayObject to add to the container
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 42
Returns:
The child that was added.
- Type
- DisplayObject
-
addChildAt(child, index)
-
Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown
Parameters:
Name Type Description childDisplayObject The child to add
indexNumber The index to place the child in
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 55
Returns:
The child that was added.
- Type
- DisplayObject
-
addMultiple(children [, silent])
-
Adds an array of existing Display Objects to this Group.
The Display Objects are automatically added to the top of this Group, and will render on-top of everything already in this Group.
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.enableBodyis set, then a physics body will be created on the objects, so long as one does not already exist.If
Group.inputEnableChildrenis set, then an Input Handler will be created on the objects, so long as one does not already exist.Parameters:
Name Type Argument Default Description childrenArray.<DisplayObject> | Phaser.Group An array of display objects or a Phaser.Group. If a Group is given then all children will be moved from it.
silentboolean <optional>
false If true the children will not dispatch the
onAddedToGroupevent.- Inherited From:
- Source:
- src/core/Group.js line 496
Returns:
The array of children or Group of children that were added to this Group.
- Type
- Array.<DisplayObject> | Phaser.Group
-
addToHash(child)
-
Adds a child of this Group into the hash array. This call will return false if the child is not a child of this Group, or is already in the hash.
Parameters:
Name Type Description childDisplayObject The display object to add to this Groups hash. Must be a member of this Group already and not present in the hash.
- Inherited From:
- Source:
- src/core/Group.js line 446
Returns:
True if the child was successfully added to the hash, otherwise false.
- Type
- boolean
-
align(width, height, cellWidth, cellHeight [, position] [, offset])
-
This method iterates through all children in the Group (regardless if they are visible or exist) and then changes their position so they are arranged in a Grid formation. Children must have the
alignTomethod in order to be positioned by this call. All default Phaser Game Objects have this.The grid dimensions are determined by the first four arguments. The
widthandheightarguments relate to the width and height of the grid respectively.For example if the Group had 100 children in it:
Group.align(10, 10, 32, 32)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.
You can choose to set either the
widthorheightvalue to -1. Doing so tells the method to keep on aligning children until there are no children left. For example if this Group had 48 children in it, the following:Group.align(-1, 8, 32, 32)... 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
positionproperty allows you to control where in each grid cell the child is positioned. This is a constant and can be one ofPhaser.TOP_LEFT(default),Phaser.TOP_CENTER,Phaser.TOP_RIGHT,Phaser.LEFT_CENTER,Phaser.CENTER,Phaser.RIGHT_CENTER,Phaser.BOTTOM_LEFT,Phaser.BOTTOM_CENTERorPhaser.BOTTOM_RIGHT.The final argument;
offsetlets you start the alignment from a specific child index.Parameters:
Name Type Argument Default Description widthinteger The width of the grid in items (not pixels). Set to -1 for a dynamic width. If -1 then you must set an explicit height value.
heightinteger The height of the grid in items (not pixels). Set to -1 for a dynamic height. If -1 then you must set an explicit width value.
cellWidthinteger The width of each grid cell, in pixels.
cellHeightinteger The height of each grid cell, in pixels.
positioninteger <optional>
The position constant. 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_CENTERorPhaser.BOTTOM_RIGHT.offsetinteger <optional>
0 Optional index to start the alignment from. Defaults to zero, the first child in the Group, but can be set to any valid child index value.
- Inherited From:
- Source:
- src/core/Group.js line 689
Returns:
True if the Group children were aligned, otherwise false.
- Type
- boolean
-
alignIn(container [, position] [, offsetX] [, offsetY])
-
Aligns this Group within another Game Object, or Rectangle, known as the '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.boundsorCamera.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.BOTTOM_CENTERandPhaser.BOTTOM_RIGHT.Groups are placed in such a way that their bounds align with the container, taking into consideration rotation and scale of its children. This allows you to neatly align Groups, irrespective of their position value.
The optional
offsetXandoffsetYarguments allow you to apply extra spacing to the final aligned position of the Group. For example:group.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)Would align the
groupto the bottom-right, but moved 20 pixels in from the corner. Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place. So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive one expands it.Parameters:
Name Type Argument Default Description containerPhaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite The Game Object or Rectangle with which to align this Group to. Can also include properties such as
World.boundsorCamera.view.positioninteger <optional>
The position constant. 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_CENTERorPhaser.BOTTOM_RIGHT.offsetXinteger <optional>
0 A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
offsetYinteger <optional>
0 A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
- Inherited From:
- Source:
- src/core/Group.js line 3018
Returns:
This Group.
- Type
- Phaser.Group
-
alignTo(parent [, position] [, offsetX] [, offsetY])
-
Aligns this Group to the side of another Game Object, or Rectangle, known as the '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.boundsorCamera.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_CENTERandPhaser.BOTTOM_RIGHT.Groups are placed in such a way that their bounds align with the parent, taking into consideration rotation and scale of the children. This allows you to neatly align Groups, irrespective of their position value.
The optional
offsetXandoffsetYarguments allow you to apply extra spacing to the final aligned position of the Group. For example:group.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)Would align the
groupto the bottom-right, but moved 20 pixels in from the corner. Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place. So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive one expands it.Parameters:
Name Type Argument Default Description parentPhaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite The Game Object or Rectangle with which to align this Group to. Can also include properties such as
World.boundsorCamera.view.positioninteger <optional>
The position constant. One of
Phaser.TOP_LEFT,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_CENTERorPhaser.BOTTOM_RIGHT.offsetXinteger <optional>
0 A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
offsetYinteger <optional>
0 A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
- Inherited From:
- Source:
- src/core/Group.js line 3060
Returns:
This Group.
- Type
- Phaser.Group
-
<protected> 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:
- src/core/Group.js line 2024
-
<protected> boot()
-
Initialises the game world.
- Source:
- src/core/World.js line 60
-
bringToTop(child)
-
Brings the given child to the top of this group so it renders above all other children.
Parameters:
Name Type Description childany The child to bring to the top of this group.
- Inherited From:
- Source:
- src/core/Group.js line 914
Returns:
The child that was moved.
- Type
- any
-
callAll(method [, context], args)
-
Calls a function, specified by name, on all on children.
The function is called for all children regardless if they are dead or alive (see callAllExists for different options). 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 Name of the function on the child to call. Deep property lookup is supported.
contextstring <optional>
null A string containing the context under which the method will be executed. Set to null to default to the child.
argsany <repeatable>
Additional parameters that will be passed to the method.
- Inherited From:
- Source:
- src/core/Group.js line 1621
-
callAllExists(callback, existsValue, parameter)
-
Calls a function, specified by name, on all children in the group who exist (or do not exist).
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 callbackstring Name of the function on the children to call.
existsValueboolean Only children with exists=existsValue will be called.
parameterany <repeatable>
Additional parameters that will be passed to the callback.
- Inherited From:
- Source:
- src/core/Group.js line 1537
-
<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.
lengthinteger The size of the array (pre-calculated in callAll).
- Inherited From:
- Source:
- src/core/Group.js line 1571
-
checkAll(key, value [, checkAlive] [, checkVisible] [, force])
-
Test 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 checked. For example: 'body.velocity.x'
valueany 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 Also return false if the property is missing or undefined (regardless of the
valueargument).- Inherited From:
- Source:
- src/core/Group.js line 1361
Returns:
- True if all eligible children have the given property value (but see
force); otherwise false.
- Type
- boolean
-
checkAny(key, value [, checkAlive] [, checkVisible])
-
Test that at least one child of this group has the given property 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 checked. For example: 'body.velocity.x'
valueany 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.
- Inherited From:
- Source:
- src/core/Group.js line 1397
Returns:
- True if at least one eligible child has the given property value; otherwise false.
- Type
- boolean
-
checkProperty(child, key, value [, force])
-
Checks a property for the given value on the child.
Parameters:
Name Type Argument Default Description childany The child to check the property value on.
keystring The property, as a string, to be checked. For example: 'body.velocity.x'
valueany The value that will be checked.
forceboolean <optional>
false Also return false if the property is missing or undefined (regardless of the
valueargument).- Inherited From:
- Source:
- src/core/Group.js line 1224
Returns:
True if
childis a child of this Group and the property was equal to value, false if not.- Type
- boolean
-
contains(child)
-
Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself.
Parameters:
Name Type Description childDisplayObject - Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 449
Returns:
- Type
- boolean
-
countDead()
-
Get the number of dead children in this group.
- Inherited From:
- Source:
- src/core/Group.js line 2443
Returns:
The number of children flagged as dead.
- Type
- integer
-
countLiving()
-
Get the number of living children in this group.
- Inherited From:
- Source:
- src/core/Group.js line 2431
Returns:
The number of children flagged as alive.
- Type
- integer
-
create(x, y [, key] [, frame] [, exists] [, index])
-
Creates a new Phaser.Sprite object and adds it to the top of this group.
Use 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, this allows you to control child ordering.
If
Group.enableBodyis set, then a physics body will be created on the object, so long as one does not already exist.If
Group.inputEnableChildrenis set, then an Input Handler will be created on the object, so long as one does not already exist.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 | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture <optional>
This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
framestring | number <optional>
If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
existsboolean <optional>
true The default exists state of the Sprite.
indexinteger <optional>
The index within the group to insert the child to. Where 0 is the bottom of the Group.
- Inherited From:
- Source:
- src/core/Group.js line 551
Returns:
The child that was created: will be a Phaser.Sprite unless #classType has been changed.
- Type
- DisplayObject
-
createMultiple(quantity, key [, frame] [, exists])
-
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 classType to change the type of object created.
You can provide an array as the
keyand / orframearguments. When you do this it will createquantitySprites 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 created in total, 25 of each. You can also have the
frameas an array:createMultiple(5, 'bricks', [0, 1, 2, 3])In the above there is one key (bricks), which is a sprite sheet. The frames array tells this method to use frames 0, 1, 2 and 3. So in total it will create 20 sprites, because the quantity was set to 5, so that is 5 brick sprites of frame 0, 5 brick sprites with frame 1, and so on.
If you set both the key and frame arguments to be arrays then understand it will create a total quantity of sprites equal to the size of both arrays times each other. I.e.:
createMultiple(20, ['diamonds', 'balls'], [0, 1, 2])The above will create 20 'diamonds' of frame 0, 20 with frame 1 and 20 with frame 2. 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
existsproperty set tofalse, and they will be positioned at 0x0, relative to theGroup.x / yvalues.If
Group.enableBodyis set, then a physics body will be created on the objects, so long as one does not already exist.If
Group.inputEnableChildrenis set, then an Input Handler will be created on the objects, so long as one does not already exist.Parameters:
Name Type Argument Default Description quantityinteger The number of Sprites to create.
keystring | array The Cache key of the image that the Sprites will use. Or an Array of keys. See the description for details on how the quantity applies when arrays are used.
frameinteger | string | array <optional>
0 If the Sprite image contains multiple frames you can specify which one to use here. Or an Array of frames. See the description for details on how the quantity applies when arrays are used.
existsboolean <optional>
false The default exists state of the Sprite.
- Inherited From:
- Source:
- src/core/Group.js line 588
Returns:
An array containing all of the Sprites that were created.
- Type
- array
-
customSort(sortHandler [, context])
-
Sort the children in the group according to custom sort function.
The
sortHandleris provided the two parameters: the two children involved in the comparison (a and b). It should return -1 ifa > b, 1 ifa < bor 0 ifa === b.Parameters:
Name Type Argument Description sortHandlerfunction The custom sort function.
contextobject <optional>
The context in which the sortHandler is called.
- Inherited From:
- Source:
- src/core/Group.js line 2000
-
<protected> 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:
- src/core/Group.js line 2056
-
destroy( [destroyChildren] [, soft])
-
Destroys this group.
Removes all children, then removes this group from its parent and nulls references.
Parameters:
Name Type Argument Default Description destroyChildrenboolean <optional>
true If true
destroywill be invoked on each removed child.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:
- src/core/Group.js line 2756
-
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 for each child.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:
- src/core/Group.js line 1482
-
filter(predicate [, checkExists])
-
Find children matching a certain predicate.
For example:
var healthyList = Group.filter(function(child, index, children) { return child.health > 10 ? true : false; }, true); healthyList.callAll('attack');Note: Currently this will skip any children which are Groups themselves.
Parameters:
Name Type Argument Default Description predicatefunction The function that each child will be evaluated against. Each child of the group will be passed to it as its first parameter, the index as the second, and the entire child array as the third
checkExistsboolean <optional>
false If true, only existing can be selected; otherwise all children can be selected and will be passed to the predicate.
- Inherited From:
- Source:
- src/core/Group.js line 1782
Returns:
Returns an array list containing all the children that the predicate returned true for
- Type
- Phaser.ArraySet
-
forEach(callback, callbackContext [, checkExists] [, args])
-
Call a function on each child in this group.
Additional arguments for the callback can be specified after the
checkExistsparameter. For example,Group.forEach(awardBonusGold, this, true, 100, 500)would invoke
awardBonusGoldfunction with the parameters(child, 100, 500).Note: This check will skip any children which are Groups themselves.
Parameters:
Name Type Argument Default Description callbackfunction The function that will be called for each applicable child. The child will be passed as the first argument.
callbackContextobject The context in which the function should be called (usually 'this').
checkExistsboolean <optional>
false If set only children matching for which
existsis true will be passed to the callback, otherwise all children will be passed.argsany <optional>
<repeatable>
(none) Additional arguments to pass to the callback function, after the child item.
- Inherited From:
- Source:
- src/core/Group.js line 1822
-
forEachAlive(callback, callbackContext [, args])
-
Call a function on each alive child in this group.
See forEach for details.
Parameters:
Name Type Argument Default Description callbackfunction The function that will be called for each applicable child. The child will be passed as the first argument.
callbackContextobject The context in which the function should be called (usually 'this').
argsany <optional>
<repeatable>
(none) Additional arguments to pass to the callback function, after the child item.
- Inherited From:
- Source:
- src/core/Group.js line 1904
-
forEachDead(callback, callbackContext [, args])
-
Call a function on each dead child in this group.
See forEach for details.
Parameters:
Name Type Argument Default Description callbackfunction The function that will be called for each applicable child. The child will be passed as the first argument.
callbackContextobject The context in which the function should be called (usually 'this').
argsany <optional>
<repeatable>
(none) Additional arguments to pass to the callback function, after the child item.
- Inherited From:
- Source:
- src/core/Group.js line 1932
-
forEachExists(callback, callbackContext [, args])
-
Call a function on each existing child in this group.
See forEach for details.
Parameters:
Name Type Argument Default Description callbackfunction The function that will be called for each applicable child. The child will be passed as the first argument.
callbackContextobject The context in which the function should be called (usually 'this').
argsany <optional>
<repeatable>
(none) Additional arguments to pass to the callback function, after the child item.
- Inherited From:
- Source:
- src/core/Group.js line 1876
-
generateTexture( [resolution] [, scaleMode], renderer)
-
Generates a RenderTexture based on this DisplayObject, which can they be used to texture other Sprites. This can be useful if your DisplayObject is static, or complicated, and needs to be reused multiple times.
Please note that no garbage collection takes place on old textures. It is up to you to destroy old textures, and references to them, so they don't linger in memory.
Parameters:
Name Type Argument Default Description resolutionnumber <optional>
1 The resolution of the texture being generated.
scaleModenumber <optional>
PIXI.scaleModes.DEFAULT See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values.
rendererPIXI.CanvasRenderer | PIXI.WebGLRenderer The renderer used to generate the texture.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 441
Returns:
- A RenderTexture containing an image of this DisplayObject at the time it was invoked.
- Type
- Phaser.RenderTexture
-
getAll( [property] [, value] [, startIndex] [, endIndex])
-
Returns all children in this Group.
You can optionally specify a matching criteria using the
propertyandvaluearguments.For example:
getAll('exists', true)would return only children that have anexistsproperty equal totrue.Optionally you can specify a start and end index. For example if this Group had 100 children, and you set
startIndexto 0 andendIndexto 50, it would return the first 50 children in the Group. Ifpropertyandvalueare also specified, only children within the given index range are searched.Parameters:
Name Type Argument Default Description propertystring <optional>
An optional property to test against the value argument.
valueany <optional>
If property is set then Child.property must strictly equal this value to be included in the results.
startIndexinteger <optional>
0 The first child index to start the search from.
endIndexinteger <optional>
The last child index to search up until.
- Inherited From:
- Source:
- src/core/Group.js line 2497
Returns:
- An array containing all, some, or none of the Children of this Group.
- Type
- array
-
getAt(index)
-
Returns the child found at the given index within this group.
Parameters:
Name Type Description indexinteger The index to return the child from.
- Inherited From:
- Source:
- src/core/Group.js line 531
Returns:
The child that was found at the given index, or -1 for an invalid index.
- Type
- DisplayObject | integer
-
getBottom()
-
Returns the child at the bottom of this group.
The bottom child the child being displayed (rendered) below every other child.
- Inherited From:
- Source:
- src/core/Group.js line 2326
Returns:
The child at the bottom of the Group.
- Type
- any
-
getBounds( [targetCoordinateSpace])
-
Retrieves the global bounds of the displayObjectContainer as a rectangle. The bounds calculation takes all visible children into consideration.
Parameters:
Name Type Argument Description targetCoordinateSpacePIXI.DisplayObject | Phaser.Matrix <optional>
Returns a rectangle that defines the area of the display object relative to the coordinate system of the targetCoordinateSpace object.
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 280
Returns:
The rectangular bounding area
- Type
- Rectangle
-
getByName(name)
-
Searches the Group for the first instance of a child with the
nameproperty matching the given argument. Should more than one child have the same name only the first instance is returned.Parameters:
Name Type Description namestring The name to search for.
- Inherited From:
- Source:
- src/core/Group.js line 1049
Returns:
The first child with a matching name, or null if none were found.
- Type
- any
-
getChildAt(index)
-
Returns the child at the specified index
Parameters:
Name Type Description indexNumber The index to get the child from
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 153
Returns:
The child at the given index, if any.
- Type
- DisplayObject
-
getChildIndex(child)
-
Returns the index position of a child DisplayObject instance
Parameters:
Name Type Description childDisplayObject The DisplayObject instance to identify
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 112
Returns:
The index position of the child display object to identify
- Type
- Number
-
getClosestTo(object [, callback] [, callbackContext])
-
Get the closest child to given Object, with optional callback to filter children.
This can be a Sprite, Group, Image or any object with public x and y properties.
'close' is determined by the distance from the objects
xandyproperties compared to the childsxandyproperties.You can use the optional
callbackargument to apply your own filter to the distance checks. If the child is closer then the previous child, it will be sent tocallbackas the first argument, with the distance as the second. The callback should returntrueif it passes your filtering criteria, otherwise it should returnfalse.Parameters:
Name Type Argument Description objectany The object used to determine the distance. This can be a Sprite, Group, Image or any object with public x and y properties.
callbackfunction <optional>
The function that each child will be evaluated against. Each child of the group will be passed to it as its first parameter, with the distance as the second. It should return
trueif the child passes the matching criteria.callbackContextobject <optional>
The context in which the function should be called (usually 'this').
- Inherited From:
- Source:
- src/core/Group.js line 2343
Returns:
The child closest to given object, or
nullif no child was found.- Type
- any
-
getFirstAlive( [createIfNull] [, x] [, y] [, key] [, frame])
-
Get the first child that is alive (
child.alive === true).This is handy for choosing a squad leader, etc.
You can use the optional argument
createIfNullto create a new Game Object if no alive ones were found in this Group.It works by calling
Group.createpassing it the parameters given to this method, and returning the new child.If a child was found ,
createIfNullisfalseand you provided the additional arguments then the child will be reset and/or have a new texture loaded on it. This is handled byGroup.resetChild.Parameters:
Name Type Argument Default Description createIfNullboolean <optional>
false If
trueand no alive children are found a new one is created.xnumber <optional>
The x coordinate to reset the child to. The value is in relation to the group.x point.
ynumber <optional>
The y coordinate to reset the child to. The value is in relation to the group.y point.
keystring | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture <optional>
This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
framestring | number <optional>
If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
- Inherited From:
- Source:
- src/core/Group.js line 2210
Returns:
The alive dead child, or
nullif none found andcreateIfNullwas false.- Type
- DisplayObject
-
getFirstDead( [createIfNull] [, x] [, y] [, key] [, frame])
-
Get the first child that is dead (
child.alive === false).This is handy for checking if everything has been wiped out and adding to the pool as needed.
You can use the optional argument
createIfNullto create a new Game Object if no dead ones were found in this Group.It works by calling
Group.createpassing it the parameters given to this method, and returning the new child.If a child was found ,
createIfNullisfalseand you provided the additional arguments then the child will be reset and/or have a new texture loaded on it. This is handled byGroup.resetChild.Parameters:
Name Type Argument Default Description createIfNullboolean <optional>
false If
trueand no dead children are found a new one is created.xnumber <optional>
The x coordinate to reset the child to. The value is in relation to the group.x point.
ynumber <optional>
The y coordinate to reset the child to. The value is in relation to the group.y point.
keystring | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture <optional>
This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
framestring | number <optional>
If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
- Inherited From:
- Source:
- src/core/Group.js line 2240
Returns:
The first dead child, or
nullif none found andcreateIfNullwas false.- Type
- DisplayObject
-
getFirstExists( [exists] [, createIfNull] [, x] [, y] [, key] [, frame])
-
Get the first display object that exists, or doesn't exist.
You can use the optional argument
createIfNullto create a new Game Object if none matching your exists argument were found in this Group.It works by calling
Group.createpassing it the parameters given to this method, and returning the new child.If a child was found ,
createIfNullisfalseand you provided the additional arguments then the child will be reset and/or have a new texture loaded on it. This is handled byGroup.resetChild.Parameters:
Name Type Argument Default Description existsboolean <optional>
true If true, find the first existing child; otherwise find the first non-existing child.
createIfNullboolean <optional>
false If
trueand no alive children are found a new one is created.xnumber <optional>
The x coordinate to reset the child to. The value is in relation to the group.x point.
ynumber <optional>
The y coordinate to reset the child to. The value is in relation to the group.y point.
keystring | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture <optional>
This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
framestring | number <optional>
If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
- Inherited From:
- Source:
- src/core/Group.js line 2176
Returns:
The first child, or
nullif none found andcreateIfNullwas false.- Type
- DisplayObject
-
getFurthestFrom(object [, callback] [, callbackContext])
-
Get the child furthest away from the given Object, with optional callback to filter children.
This can be a Sprite, Group, Image or any object with public x and y properties.
'furthest away' is determined by the distance from the objects
xandyproperties compared to the childsxandyproperties.You can use the optional
callbackargument to apply your own filter to the distance checks. If the child is closer then the previous child, it will be sent tocallbackas the first argument, with the distance as the second. The callback should returntrueif it passes your filtering criteria, otherwise it should returnfalse.Parameters:
Name Type Argument Description objectany The object used to determine the distance. This can be a Sprite, Group, Image or any object with public x and y properties.
callbackfunction <optional>
The function that each child will be evaluated against. Each child of the group will be passed to it as its first parameter, with the distance as the second. It should return
trueif the child passes the matching criteria.callbackContextobject <optional>
The context in which the function should be called (usually 'this').
- Inherited From:
- Source:
- src/core/Group.js line 2387
Returns:
The child furthest from the given object, or
nullif no child was found.- Type
- any
-
getIndex(child)
-
Get the index position of the given child in this group, which should match the child's
zproperty.Parameters:
Name Type Description childany The child to get the index for.
- Inherited From:
- Source:
- src/core/Group.js line 1036
Returns:
The index of the child or -1 if it's not a member of this group.
- Type
- integer
-
getLocalBounds()
-
Retrieves the non-global local bounds of the displayObjectContainer as a rectangle without any transformations. The calculation takes all visible children into consideration.
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 437
Returns:
The rectangular bounding area
- Type
- Rectangle
-
getRandom( [startIndex] [, length])
-
Returns a random child from the group.
Parameters:
Name Type Argument Default Description startIndexinteger <optional>
0 Offset from the front of the group (lowest child).
lengthinteger <optional>
(to top) Restriction on the number of values you want to randomly select from.
- Inherited From:
- Source:
- src/core/Group.js line 2455
Returns:
A random child of this Group.
- Type
- any
-
getRandomExists( [startIndex] [, endIndex])
-
Returns a random child from the Group that has
existsset totrue.Optionally you can specify a start and end index. For example if this Group had 100 children, and you set
startIndexto 0 andendIndexto 50, it would return a random child from only the first 50 children in the Group.Parameters:
Name Type Argument Default Description startIndexinteger <optional>
0 The first child index to start the search from.
endIndexinteger <optional>
The last child index to search up to.
- Inherited From:
- Source:
- src/core/Group.js line 2477
Returns:
A random child of this Group that exists.
- Type
- any
-
getTop()
-
Return the child at the top of this group.
The top child is the child displayed (rendered) above every other child.
- Inherited From:
- Source:
- src/core/Group.js line 2309
Returns:
The child at the top of the Group.
- Type
- any
-
hasProperty(child, key)
-
Checks if the child has the given property.
Will scan up to 4 levels deep only.
Parameters:
Name Type Description childany The child to check for the existence of the property on.
keyArray.<string> An array of strings that make up the property.
- Inherited From:
- Source:
- src/core/Group.js line 1111
Returns:
True if the child has the property, otherwise false.
- Type
- boolean
-
iterate(key, value, returnType [, callback] [, callbackContext] [, args])
-
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 tovalueaccording 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
argsis 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 keystring The child property to check, i.e. 'exists', 'alive', 'health'
valueany A child matches if
child[key] === valueis true.returnTypeinteger How to iterate the children and what to return.
callbackfunction <optional>
null Optional function that will be called on each matching child. The matched child is supplied as the first argument.
callbackContextobject <optional>
The context in which the function should be called (usually 'this').
argsArray.<any> <optional>
(none) The arguments supplied to to the callback; the first array index (argument) will be replaced with the matched child.
- Inherited From:
- Source:
- src/core/Group.js line 2081
Returns:
Returns either an integer (for RETURN_TOTAL), the first matched child (for RETURN_CHILD), or null.
- Type
- any
-
killAll()
-
Kills all children having exists=true.
- Inherited From:
- Source:
- src/core/Group.js line 1499
-
moveAll(group [, silent])
-
Moves all children from this Group to the Group given.
Parameters:
Name Type Argument Default Description groupPhaser.Group The new Group to which the children will be moved to.
silentboolean <optional>
false If true the children will not dispatch the
onAddedToGroupevent for the new Group.- Inherited From:
- Source:
- src/core/Group.js line 2591
Returns:
The Group to which all the children were moved.
- Type
- Phaser.Group
-
moveDown(child)
-
Moves the given child down one place in this group unless it's already at the bottom.
Parameters:
Name Type Description childany The child to move down in the group.
- Inherited From:
- Source:
- src/core/Group.js line 976
Returns:
The child that was moved.
- Type
- any
-
moveUp(child)
-
Moves the given child up one place in this group unless it's already at the top.
Parameters:
Name Type Description childany The child to move up in the group.
- Inherited From:
- Source:
- src/core/Group.js line 952
Returns:
The child that was moved.
- Type
- any
-
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 for each child.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:
- src/core/Group.js line 1465
-
next()
-
Advances the group cursor to the next (higher) object in the group.
If the cursor is at the end of the group (top child) it is moved the start of the group (bottom child).
- Inherited From:
- Source:
- src/core/Group.js line 840
Returns:
The child the cursor now points to.
- Type
- any
-
<protected> postUpdate()
-
The core postUpdate - as called by World.
- Inherited From:
- Source:
- src/core/Group.js line 1761
-
<protected> preUpdate()
-
The core preUpdate - as called by World.
- Inherited From:
- Source:
- src/core/Group.js line 1694
-
previous()
-
Moves the group cursor to the previous (lower) child in the group.
If the cursor is at the start of the group (bottom child) it is moved to the end (top child).
- Inherited From:
- Source:
- src/core/Group.js line 869
Returns:
The child the cursor now points to.
- Type
- any
-
remove(child [, destroy] [, silent])
-
Removes the given child from this group.
This will dispatch an
onRemovedFromGroupevent from the child (if it has one), and optionally destroy the child.If the group cursor was referring to the removed child it is updated to refer to the next child.
Parameters:
Name Type Argument Default Description childany The child to remove.
destroyboolean <optional>
false If true
destroywill be invoked on the removed child.silentboolean <optional>
false If true the the child will not dispatch the
onRemovedFromGroupevent.- Inherited From:
- Source:
- src/core/Group.js line 2543
Returns:
true if the child was removed from this group, otherwise false.
- Type
- boolean
-
removeAll( [destroy] [, silent] [, destroyTexture])
-
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.
Parameters:
Name Type Argument Default Description destroyboolean <optional>
false If true
destroywill be invoked on each removed child.silentboolean <optional>
false If true the children will not dispatch their
onRemovedFromGroupevents.destroyTextureboolean <optional>
false If true, and if the
destroyargument is also true, the BaseTexture belonging to the Child is also destroyed. Note that if another Game Object is sharing the same BaseTexture it will invalidate it.- Inherited From:
- Source:
- src/core/Group.js line 2620
-
removeBetween(startIndex [, endIndex] [, destroy] [, silent])
-
Removes all children from this group whose index falls beteen the given startIndex and endIndex values.
Parameters:
Name Type Argument Default Description startIndexinteger The index to start removing children from.
endIndexinteger <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 If true
destroywill be invoked on each removed child.silentboolean <optional>
false If true the children will not dispatch their
onRemovedFromGroupevents.- Inherited From:
- Source:
- src/core/Group.js line 2668
-
removeChild(child)
-
Removes a child from the container.
Parameters:
Name Type Description childDisplayObject The DisplayObject to remove
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 171
Returns:
The child that was removed.
- Type
- DisplayObject
-
removeChildAt(index)
-
Removes a child from the specified index position.
Parameters:
Name Type Description indexNumber The index to get the child from
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 191
Returns:
The child that was removed.
- Type
- DisplayObject
-
removeChildren(beginIndex, endIndex)
-
Removes all children from this container that are within the begin and end indexes.
Parameters:
Name Type Description beginIndexNumber The beginning position. Default value is 0.
endIndexNumber The ending position. Default value is size of the container.
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 213
-
removeFromHash(child)
-
Removes a child of this Group from the hash array. This call will return false if the child is not in the hash.
Parameters:
Name Type Description childDisplayObject The display object to remove from this Groups hash. Must be a member of this Group and in the hash.
- Inherited From:
- Source:
- src/core/Group.js line 471
Returns:
True if the child was successfully removed from the hash, otherwise false.
- Type
- boolean
-
replace(oldChild, newChild)
-
Replaces a child of this Group with the given newChild. The newChild cannot be a member of this Group.
If
Group.enableBodyis set, then a physics body will be created on the object, so long as one does not already exist.If
Group.inputEnableChildrenis set, then an Input Handler will be created on the object, so long as one does not already exist.Parameters:
Name Type Description oldChildany The child in this group that will be replaced.
newChildany The child to be inserted into this group.
- Inherited From:
- Source:
- src/core/Group.js line 1072
Returns:
Returns the oldChild that was replaced within this group.
- Type
- any
-
resetAll( [x] [, y] [, key] [, frame] [, checkExists])
-
Calls resetChild on each child (or each existing child).
Parameters:
Name Type Argument Default Description xnumber <optional>
The x coordinate to reset each child to. The value is in relation to the group.x point.
ynumber <optional>
The y coordinate to reset each child to. The value is in relation to the group.y point.
keystring | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture <optional>
The image or texture used by the Sprite during rendering.
framestring | number <optional>
The frame of a sprite sheet or texture atlas.
checkExistsboolean <optional>
false Reset only existing children.
- Inherited From:
- Source:
- src/core/Group.js line 1521
-
resetChild(child [, x] [, y] [, key] [, frame])
-
Takes a child and if the
xandyarguments are given it callschild.reset(x, y)on it.If the
keyand optionally theframearguments are given, it callschild.loadTexture(key, frame)on it.The two operations are separate. For example if you just wish to load a new texture then pass
nullas the x and y values.Parameters:
Name Type Argument Description childDisplayObject The child to reset and/or load the texture on.
xnumber <optional>
The x coordinate to reset the child to. The value is in relation to the group.x point.
ynumber <optional>
The y coordinate to reset the child to. The value is in relation to the group.y point.
keystring | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture <optional>
This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
framestring | number <optional>
If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
- Inherited From:
- Source:
- src/core/Group.js line 2270
Returns:
The child that was reset: usually a Phaser.Sprite.
- Type
- DisplayObject
-
resetCursor( [index])
-
Sets the group cursor to the first child 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 indexinteger <optional>
0 Set the cursor to point to a specific index.
- Inherited From:
- Source:
- src/core/Group.js line 813
Returns:
The child the cursor now points to.
- Type
- any
-
resize(width, height)
-
Updates the size of this world. Note that this doesn't modify the world x/y coordinates, just the width and height.
Parameters:
Name Type Description widthnumber New width of the game world in pixels.
heightnumber New height of the game world in pixels.
- Source:
- src/core/World.js line 125
-
reverse()
-
Reverses all children in this group.
This operation applies only to immediate children and does not propagate to subgroups.
- Inherited From:
- Source:
- src/core/Group.js line 1022
-
reviveAll()
-
Revives all children having exists=false.
- Inherited From:
- Source:
- src/core/Group.js line 1510
-
scatter( [rect] [, checkExists])
-
Places each child at a random position within the given Rectangle (or the World bounds).
Parameters:
Name Type Argument Default Description rectPhaser.Rectangle <optional>
this.game.world.bounds A Rectangle. If omitted Phaser.World#bounds is used.
checkExistsboolean <optional>
false Place only children with exists=true.
- Inherited From:
- Source:
- src/core/Group.js line 2723
-
sendToBack(child)
-
Sends the given child to the bottom of this group so it renders below all other children.
Parameters:
Name Type Description childany The child to send to the bottom of this group.
- Inherited From:
- Source:
- src/core/Group.js line 933
Returns:
The child that was moved.
- Type
- any
-
set(child, key, value [, checkAlive] [, checkVisible] [, operation] [, force])
-
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'
valueany 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.
operationinteger <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:
- src/core/Group.js line 1254
Returns:
True if the property was set, false if not.
- Type
- boolean
-
setAll(key, value [, checkAlive] [, checkVisible] [, operation] [, force])
-
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'
valueany 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.
operationinteger <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:
- src/core/Group.js line 1285
-
setAllChildren(key, value [, checkAlive] [, checkVisible] [, operation] [, force])
-
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
setAllthe 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'
valueany 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.
operationinteger <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:
- src/core/Group.js line 1320
-
setBounds(x, y, width, height)
-
Updates the size of this world and sets World.x/y to the given values The Camera bounds and Physics bounds (if set) are also updated to match the new World bounds.
Parameters:
Name Type Description xnumber Top left most corner of the world.
ynumber Top left most corner of the world.
widthnumber New width of the game world in pixels.
heightnumber New height of the game world in pixels.
- Source:
- src/core/World.js line 94
-
setChildIndex(child, index)
-
Changes the position of an existing child in the display object container
Parameters:
Name Type Description childDisplayObject The child DisplayObject instance for which you want to change the index number
indexNumber The resulting index number for the child display object
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 132
-
setProperty(child, key, value [, operation] [, force])
-
Sets a property to the given value on the child. The operation parameter controls how the value is set.
The operations are:
- 0: set the existing value to the given value; if force is
truea new property will be created if needed - 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 childany The child to set the property value on.
keyarray An array of strings that make up the property that will be set.
valueany The value that will be set.
operationinteger <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:
- src/core/Group.js line 1146
Returns:
True if the property was set, false if not.
- Type
- boolean
- 0: set the existing value to the given value; if force is
-
shuffle()
-
Orders this Group's children randomly.
This can be more efficient than calling getRandom repeatedly.
- Inherited From:
- Source:
- src/core/Group.js line 2742
-
shutdown()
-
Destroyer of worlds.
- Source:
- src/core/World.js line 158
-
sort( [key] [, order])
-
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 yourState.update().Internally this uses a standard JavaScript Array sort, so everything that applies there also applies here, including alphabetical sorting, mixing strings and numbers, and Unicode sorting. See MDN for more details.
Parameters:
Name Type Argument Default Description keystring <optional>
'z' The name of the property to sort on. Defaults to the objects z-depth value.
orderinteger <optional>
Phaser.Group.SORT_ASCENDING Order ascending (SORT_ASCENDING) or descending (SORT_DESCENDING).
- Inherited From:
- Source:
- src/core/Group.js line 1960
-
<protected> stateChange()
-
Called whenever the State changes or resets.
It resets the world.x and world.y coordinates back to zero, then resets the Camera.
- Source:
- src/core/World.js line 76
-
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 for each child.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:
- src/core/Group.js line 1448
-
swap(child1, child2)
-
Swaps the position of two children in this group.
Both children must be in this group, a child cannot be swapped with itself, and unparented children cannot be swapped.
Parameters:
Name Type Description child1any The first child to swap.
child2any The second child to swap.
- Inherited From:
- Source:
- src/core/Group.js line 898
-
swapChildren(child, child2)
-
Swaps the position of 2 Display Objects within this container.
Parameters:
Name Type Description childDisplayObject child2DisplayObject - Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 85
-
toGlobal(position)
-
Calculates the global position of this DisplayObject, based on the position given.
Parameters:
Name Type Description positionPIXI.Point The global position to calculate from.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 483
Returns:
- A point object representing the position of this DisplayObject based on the global position given.
- Type
- PIXI.Point
-
toLocal(position [, from])
-
Calculates the local position of this DisplayObject, relative to another point.
Parameters:
Name Type Argument Description positionPIXI.Point The world origin to calculate from.
fromPIXI.DisplayObject <optional>
An optional DisplayObject to calculate the global position from.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 498
Returns:
- A point object representing the position of this DisplayObject based on the global position given.
- Type
- PIXI.Point
-
<protected> update()
-
The core update - as called by World.
Children with
exists = falseare updated unless updateOnlyExistingChildren is true.- Inherited From:
- Source:
- src/core/Group.js line 1733
-
updateCache()
-
If this DisplayObject has a cached Sprite, this method generates and updates it.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 469
Returns:
- A reference to this DisplayObject.
- Type
- PIXI.DisplayObject
-
updateTransform( [parent])
-
Updates the transform matrix this DisplayObject uses for rendering.
If the object has no parent, and no parent parameter is provided, it will default to Phaser.Game.World as the parent transform to use. If that is unavailable the transform fails to take place.
The
parentparameter has priority over the actual parent. Use it as a parent override. Setting it does not change the actual parent of this DisplayObject.Calling this method updates the
worldTransform,worldAlpha,worldPosition,worldScaleandworldRotationproperties.If a
transformCallbackhas been specified, it is called at the end of this method, and is passed the new, updated, worldTransform property, along with the parent transform used.Parameters:
Name Type Argument Description parentPIXI.DisplayObjectContainer <optional>
Optional parent to calculate this DisplayObjects transform from.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 289
Returns:
- A reference to this DisplayObject.
- Type
- PIXI.DisplayObject
-
<protected> updateZ()
-
Internal method that re-applies all of the children's Z values.
This must be called whenever children ordering is altered so that their
zindices are correctly updated.- Inherited From:
- Source:
- src/core/Group.js line 670
-
wrap(sprite [, padding] [, useBounds] [, horizontal] [, vertical])
-
This will take the given game object and check if its x/y coordinates fall outside of the world bounds. If they do it will reposition the object to the opposite side of the world, creating a wrap-around effect. If sprite has a P2 body then the body (sprite.body) should be passed as first parameter to the function.
Please understand there are limitations to this method. For example if you have scaled the World then objects won't always be re-positioned correctly, and you'll need to employ your own wrapping function.
Parameters:
Name Type Argument Default Description spritePhaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Text The object you wish to wrap around the world bounds.
paddingnumber <optional>
0 Extra padding added equally to the sprite.x and y coordinates before checking if within the world bounds. Ignored if useBounds is true.
useBoundsboolean <optional>
false If useBounds is false wrap checks the object.x/y coordinates. If true it does a more accurate bounds check, which is more expensive.
horizontalboolean <optional>
true If horizontal is false, wrap will not wrap the object.x coordinates horizontally.
verticalboolean <optional>
true If vertical is false, wrap will not wrap the object.y coordinates vertically.
- Source:
- src/core/World.js line 170
-
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 indexinteger 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:
- src/core/Group.js line 1000