Class: Stage

Phaser. Stage

new Stage(game)

The Stage controls root level display objects upon which everything is displayed. It also handles browser visibility handling and the pausing due to loss of focus.

Parameters:
Name Type Description
game Phaser.Game

Game reference to the currently running game.

Source:
src/core/Stage.js line 16

Extends

Members

alpha : number

The alpha value of this DisplayObject. A value of 1 is fully opaque. A value of 0 is transparent. Please note that an object with an alpha value of 0 is skipped during the render pass.

The value of this property does not reflect any alpha values set further up the display list. To obtain that value please see the worldAlpha property.

Type:
  • number
Inherited From:
Default Value:
  • 1
Source:
src/pixi/display/DisplayObject.js line 73

backgroundColor : number | string

Gets and sets the background color of the stage. The color can be given as a number: 0xff0000 or a hex string: '#ff0000'

Type:
  • number | string
Source:
src/core/Stage.js line 442
See:

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 to null to remove an existing cached bitmap.

Type:
  • boolean
Inherited From:
Source:
src/pixi/display/DisplayObject.js line 791

<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

currentRenderOrderID : number

Reset each frame, keeps a count of the total number of objects updated.

Type:
  • number
Source:
src/core/Stage.js line 65

disableVisibilityChange : boolean

By default if the browser tab loses focus the game will pause. You can stop that behavior by setting this property to true. Note that the browser can still elect to pause your game if it wishes to do so, for example swapping to another browser tab. This will cause the RAF callback to halt, effectively pausing your game, even though no in-game pause event is triggered if you enable this property.

Type:
  • boolean
Source:
src/core/Stage.js line 40

exists : boolean

If exists is true the Stage and all children are updated, otherwise it is skipped.

Type:
  • boolean
Default Value:
  • true
Source:
src/core/Stage.js line 46

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 205

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 740

game : Phaser.Game

A reference to the currently running Game.

Type:
Source:
src/core/Stage.js line 21

height : Number

The height of the displayObjectContainer, setting this will actually modify the scale to achieve the value set

Type:
  • Number
Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 606

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 99

ignoreChildInput : boolean

If ignoreChildInput is false it will allow this objects children to be considered as valid for Input events.

If this property is true then 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

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 to null to remove an existing mask.

Type:
Inherited From:
Source:
src/pixi/display/DisplayObject.js line 707

name : string

The name of this object.

Type:
  • string
Default Value:
  • _stage_root
Source:
src/core/Stage.js line 29

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

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

Type:
  • PIXI.Point
Inherited From:
Source:
src/pixi/display/DisplayObject.js line 29

renderable : boolean

Should this DisplayObject be rendered by the renderer? An object with a renderable value of false is skipped during the render pass.

Type:
  • boolean
Inherited From:
Source:
src/pixi/display/DisplayObject.js line 108

rotation : number

The rotation of this DisplayObject. The value is given, and expressed, in radians, and is based on a right-handed orientation.

The value of this property does not reflect any rotation happening further up the display list. To obtain that value please see the worldRotation property.

Type:
  • number
Inherited From:
Source:
src/pixi/display/DisplayObject.js line 61

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

Type:
  • PIXI.Point
Inherited From:
Source:
src/pixi/display/DisplayObject.js line 41

smoothed : boolean

Enable or disable texture smoothing for all objects on this Stage. Only works for bitmap/image textures. Smoothing is enabled by default. Set to true to smooth all sprites rendered on this Stage, or false to disable smoothing (great for pixel art)

Type:
  • boolean
Source:
src/core/Stage.js line 461

visible : boolean

The visibility of this DisplayObject. A value of false makes the object invisible. A value of true makes it visible.

An object with a visible value of false is skipped during the render pass. Equally a DisplayObject with visible false will not render any of its children.

The value of this property does not reflect any visible values set further up the display list. To obtain that value please see the worldVisible property.

Objects that are not worldVisible do not update their worldPosition.

Type:
  • boolean
Inherited From:
Default Value:
  • true
Source:
src/pixi/display/DisplayObject.js line 90

width : Number

The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set

Type:
  • Number
Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 576

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

Note: This property is only updated at the end of the updateTransform call, 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:
Overrides:
Source:
src/pixi/display/DisplayObject.js line 136

<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 updateTransform call, 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 166

<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 updateTransform call, 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 196

<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 updateTransform call, 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 181

worldVisible : boolean

Indicates if this DisplayObject is visible, based on it, and all of its parents, visible property values.

Type:
  • boolean
Inherited From:
Source:
src/pixi/display/DisplayObject.js line 666

x : number

The horizontal position of the DisplayObject, in pixels, relative to its parent. If you need the world position of the DisplayObject, use DisplayObject.worldPosition instead.

Type:
  • number
Inherited From:
Source:
src/pixi/display/DisplayObject.js line 626

y : number

The vertical position of the DisplayObject, in pixels, relative to its parent. If you need the world position of the DisplayObject, use DisplayObject.worldPosition instead.

Type:
  • number
Inherited From:
Source:
src/pixi/display/DisplayObject.js line 646

Methods

add(child [, silent] [, index])

Adds an existing object to the Stage.

The child is automatically added to the front of the Stage, 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 object was already on the Stage, it is simply returned, and nothing else happens to it.

Parameters:
Name Type Argument Description
child DisplayObject

The display object to add as a child.

silent boolean <optional>

Unused. Kept for compatibility with Phaser.Group#add.

index integer <optional>

The index to insert the object to.

Source:
src/core/Stage.js line 403
Returns:

The child that was added to the group.

Type
DisplayObject

addChild(child)

Adds a child to the container.

Parameters:
Name Type Description
child DisplayObject

The DisplayObject to add to the container

Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 41
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
child DisplayObject

The child to add

index Number

The index to place the child in

Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 53
Returns:

The child that was added.

Type
DisplayObject

checkVisibility()

Starts a page visibility event listener running, or window.onpagehide/onpageshow if not supported by the browser. Also listens for window.onblur and window.onfocus.

Source:
src/core/Stage.js line 223

contains(child)

Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself.

Parameters:
Name Type Description
child DisplayObject
Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 456
Returns:
Type
boolean

destroy()

Destroys the Stage and removes event listeners.

Overrides:
Source:
src/core/Stage.js line 382

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
resolution number <optional>
1

The resolution of the texture being generated.

scaleMode number <optional>
PIXI.scaleModes.DEFAULT

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

renderer PIXI.CanvasRenderer | PIXI.WebGLRenderer

The renderer used to generate the texture.

Inherited From:
Source:
src/pixi/display/DisplayObject.js line 443
Returns:
  • A RenderTexture containing an image of this DisplayObject at the time it was invoked.
Type
Phaser.RenderTexture

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
targetCoordinateSpace PIXI.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 289
Returns:

The rectangular bounding area

Type
Rectangle

getChildAt(index)

Returns the child at the specified index

Parameters:
Name Type Description
index Number

The index to get the child from

Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 147
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
child DisplayObject

The DisplayObject instance to identify

Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 108
Returns:

The index position of the child display object to identify

Type
Number

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 445
Returns:

The rectangular bounding area

Type
Rectangle

<protected> parseConfig(config)

Parses a Game configuration object.

Parameters:
Name Type Description
config object

The configuration object to parse.

Source:
src/core/Stage.js line 100

postUpdate()

This is called automatically before the renderer runs and after the plugins have updated. In postUpdate this is where all the final physics calculations and object positioning happens. The objects are processed in the order of the display list.

Source:
src/core/Stage.js line 177

preUpdate()

This is called automatically after the plugins preUpdate and before the State.update. Most objects have preUpdate methods and it's where initial movement and positioning is done.

Overrides:
Source:
src/core/Stage.js line 135

removeChild(child)

Removes a child from the container.

Parameters:
Name Type Description
child DisplayObject

The DisplayObject to remove

Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 164
Returns:

The child that was removed.

Type
DisplayObject

removeChildAt(index)

Removes a child from the specified index position.

Parameters:
Name Type Description
index Number

The index to get the child from

Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 183
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
beginIndex Number

The beginning position. Default value is 0.

endIndex Number

The ending position. Default value is size of the container.

Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 224

setBackgroundColor(color)

Sets the background color for the Stage.

The color can be given as a hex string ('#RRGGBB'), a CSS color string ('rgb(r,g,b)'), or a numeric value (0xRRGGBB).

An alpha channel is not supported and will be ignored.

If you've set your game to be transparent then calls to setBackgroundColor are ignored.

If Phaser.Game#clearBeforeRender is off then the background color won't appear.

Parameters:
Name Type Description
color number | string

The color of the background.

Source:
src/core/Stage.js line 354

setChildIndex(child, index)

Changes the position of an existing child in the display object container

Parameters:
Name Type Description
child DisplayObject

The child DisplayObject instance for which you want to change the index number

index Number

The resulting index number for the child display object

Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 127

swapChildren(child, child2)

Swaps the position of 2 Display Objects within this container.

Parameters:
Name Type Description
child DisplayObject
child2 DisplayObject
Inherited From:
Source:
src/pixi/display/DisplayObjectContainer.js line 82

toGlobal(position)

Calculates the global position of this DisplayObject, based on the position given.

Parameters:
Name Type Description
position PIXI.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
position PIXI.Point

The world origin to calculate from.

from PIXI.DisplayObject <optional>

An optional DisplayObject to calculate the global position from.

Inherited From:
Source:
src/pixi/display/DisplayObject.js line 497
Returns:
  • A point object representing the position of this DisplayObject based on the global position given.
Type
PIXI.Point

update()

This is called automatically after the State.update, but before particles or plugins update.

Source:
src/core/Stage.js line 161

updateCache()

If this DisplayObject has a cached Sprite, this method generates and updates it.

Inherited From:
Source:
src/pixi/display/DisplayObject.js line 470
Returns:
  • A reference to this DisplayObject.
Type
PIXI.DisplayObject

updateTransform()

Updates the transforms for all objects on the display list. This overrides the Pixi default as we don't need the interactionManager, but do need the game property check.

Overrides:
Source:
src/core/Stage.js line 207

visibilityChange(event)

This method is called when the document visibility is changed.

Parameters:
Name Type Description
event Event

Its type will be used to decide whether the game should be paused or not.

Source:
src/core/Stage.js line 311

phaser-ce@2.20.1 is on GitHub and NPM

Documentation generated by JSDoc 3.6.11 on 2024-10-05 using Tomorrow.