Constructor

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.

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.

cacheAsBitmap : boolean

Set if this display object is cached as a bitmap.
This basically takes a snap shot of the display object as it is at that moment. It can provide a performance benefit for complex static displayObjects.
To remove simply set this property to 'null'

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 fixedToCamera then the offset here is in addition to that and should typically be disabled.

classType : Object

Any object may be used but it should extend either Sprite or Image and accept the same constructor arguments:
when a new object is created it is passed the following parameters to its constructor: (game, x, y, key, frame).

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)

height : number

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)

[readonly] length : integer

Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it.
In PIXI a regular mask must be a PIXI.Graphics object. This allows for much faster masking in canvas as it utilises shape clipping.
To remove a mask, set this property to null.

Parameters

Returns

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

method

string

Name of the function on the child to call. Deep property lookup is supported.

context

string

<optional>

null

A string containing the context under which the method will be executed. Set to null to default to the child.

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.

frame

string
|
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.

Useful function that returns a texture of the displayObject object that can then be used to create sprites
This can be quite useful if your displayObject is static / complicated and needs to be reused multiple times.

Parameters

Name

Type

Description

resolution

Number

The resolution of the texture being generated

scaleMode

Number

See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values

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.

frame

string
|
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.

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.

frame

string
|
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.

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.

frame

string
|
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.

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.

frame

string
|
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.

Returns

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

key

string

The property, as a string, to be set. For example: 'body.velocity.x'

value

any

The value that will be set.

checkAlive

boolean

<optional>

false

If set then only children with alive=true will be updated. This includes any Groups that are children.

checkVisible

boolean

<optional>

false

If set then only children with visible=true will be updated. This includes any Groups that are children.

operation

integer

<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.

force

boolean

<optional>

false

If force is 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.

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 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

key

string

The property, as a string, to be set. For example: 'body.velocity.x'

value

any

The value that will be set.

checkAlive

boolean

<optional>

false

If set then only children with alive=true will be updated. This includes any Groups that are children.

checkVisible

boolean

<optional>

false

If set then only children with visible=true will be updated. This includes any Groups that are children.

operation

integer

<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.

force

boolean

<optional>

false

If force is 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.

shutdown()

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 your State.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

key

string

<optional>

'z'

The name of the property to sort on. Defaults to the objects z-depth value.

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.