Phaser API Documentation

  Version: 
Filter
Namespace: Depth
Phaser.GameObjects.Components.Depth

Members

<private> _depth: number
Focus
Focus

Description:

Private internal value. Holds the depth of the Game Object.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
depth: number
Focus
Focus

Description:

The depth of this Game Object within the Scene. Ensure this value is only ever set to a number data-type.

The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order of Game Objects, without actually moving their position in the display list.

The default depth is zero. A Game Object with a higher depth value will always render in front of one with a lower value.

Setting the depth will queue a depth sort event within the Scene.

Type:
number
Since: 3.0.0
Focus
Focus

Methods

setDepth(value)
Focus
Focus

Description:

The depth of this Game Object within the Scene.

The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order of Game Objects, without actually moving their position in the display list.

The default depth is zero. A Game Object with a higher depth value will always render in front of one with a lower value.

Setting the depth will queue a depth sort event within the Scene.

Parameters:

name type description
value number

The depth of this Game Object. Ensure this value is only ever a number data-type.

Returns:
Description:

This Game Object instance.

Since: 3.0.0
Focus
Focus
setToTop()
Focus
Focus

Description:

Sets this Game Object to be at the top of the display list, or the top of its parent container.

Being at the top means it will render on-top of everything else.

This method does not change this Game Objects depth value, it simply alters its list position.

Returns:
Description:

This Game Object instance.

Since: 3.85.0
Focus
Focus
setToBack()
Focus
Focus

Description:

Sets this Game Object to the back of the display list, or the back of its parent container.

Being at the back means it will render below everything else.

This method does not change this Game Objects depth value, it simply alters its list position.

Returns:
Description:

This Game Object instance.

Since: 3.85.0
Focus
Focus
setAbove(gameObject)
Focus
Focus

Description:

Move this Game Object so that it appears above the given Game Object.

This means it will render immediately after the other object in the display list.

Both objects must belong to the same display list, or parent container.

This method does not change this Game Objects depth value, it simply alters its list position.

Parameters:

name type description
gameObject Phaser.GameObjects.GameObject

The Game Object that this Game Object will be moved to be above.

Returns:
Description:

This Game Object instance.

Since: 3.85.0
Focus
Focus
setBelow(gameObject)
Focus
Focus

Description:

Move this Game Object so that it appears below the given Game Object.

This means it will render immediately under the other object in the display list.

Both objects must belong to the same display list, or parent container.

This method does not change this Game Objects depth value, it simply alters its list position.

Parameters:

name type description
gameObject Phaser.GameObjects.GameObject

The Game Object that this Game Object will be moved to be below.

Returns:
Description:

This Game Object instance.

Since: 3.85.0
Focus
Focus