Phaser API Documentation

  Version: 
Filter

A Geometry Mask can be applied to a Game Object to hide any pixels of it which don't intersect a visible pixel from the geometry mask. The mask is essentially a clipping path which can only make a masked pixel fully visible or fully invisible without changing its alpha (opacity).

A Geometry Mask uses a Graphics Game Object to determine which pixels of the masked Game Object(s) should be clipped. For any given point of a masked Game Object's texture, the pixel will only be displayed if the Graphics Game Object of the Geometry Mask has a visible pixel at the same position. The color and alpha of the pixel from the Geometry Mask do not matter.

The Geometry Mask's location matches the location of its Graphics object, not the location of the masked objects. Moving or transforming the underlying Graphics object will change the mask (and affect the visibility of any masked objects), whereas moving or transforming a masked object will not affect the mask. You can think of the Geometry Mask (or rather, of its Graphics object) as an invisible curtain placed in front of all masked objects which has its own visual properties and, naturally, respects the camera's visual properties, but isn't affected by and doesn't follow the masked objects by itself.

Constructor:

new GeometryMask(scene, graphicsGeometry)

Parameters:

name type description
scene Phaser.Scene

This parameter is not used.

graphicsGeometry Phaser.GameObjects.Graphics

The Graphics Game Object to use for the Geometry Mask. Doesn't have to be in the Display List.

Since: 3.0.0

Members

Description:

The Graphics object which describes the Geometry Mask.

Type:
Since: 3.0.0
Focus
Focus
invertAlpha: boolean
Focus
Focus

Description:

Similar to the BitmapMasks invertAlpha setting this to true will then hide all pixels drawn to the Geometry Mask.

This is a WebGL only feature.

Type:
boolean
Since: 3.16.0
Focus
Focus
<readonly> isStencil: boolean
Focus
Focus

Description:

Is this mask a stencil mask?

Type:
boolean
Since: 3.17.0
Focus
Focus
<private> level: boolean
Focus
Focus

Description:

The current stencil level.

Type:
boolean
Since: 3.17.0
Focus
Focus

Methods

applyStencil(renderer, camera, inc)
Focus
Focus

Description:

Applies the current stencil mask to the renderer.

Parameters:

name type description
renderer Phaser.Renderer.WebGL.WebGLRenderer

The WebGL Renderer instance to draw to.

camera Phaser.Cameras.Scene2D.Camera

The camera the Game Object is being rendered through.

inc boolean

Is this an INCR stencil or a DECR stencil?

Since: 3.17.0
Focus
Focus
destroy()
Focus
Focus

Description:

Destroys this GeometryMask and nulls any references it holds.

Note that if a Game Object is currently using this mask it will not automatically detect you have destroyed it, so be sure to call clearMask on any Game Object using it, before destroying it.

Since: 3.7.0
Focus
Focus
postRenderCanvas(renderer)
Focus
Focus

Description:

Restore the canvas context's previous clipping path, thus turning off the mask for it.

Parameters:

name type description
renderer Phaser.Renderer.Canvas.CanvasRenderer

The Canvas Renderer instance being restored.

Since: 3.0.0
Focus
Focus
postRenderWebGL(renderer)
Focus
Focus

Description:

Flushes all rendered pixels and disables the stencil test of a WebGL context, thus disabling the mask for it.

Parameters:

name type description
renderer Phaser.Renderer.WebGL.WebGLRenderer

The WebGL Renderer instance to draw flush.

Since: 3.0.0
Focus
Focus
preRenderCanvas(renderer, mask, camera)
Focus
Focus

Description:

Sets the clipping path of a 2D canvas context to the Geometry Mask's underlying Graphics object.

Parameters:

name type description
renderer Phaser.Renderer.Canvas.CanvasRenderer

The Canvas Renderer instance to set the clipping path on.

mask Phaser.GameObjects.GameObject

The Game Object being rendered.

camera Phaser.Cameras.Scene2D.Camera

The camera the Game Object is being rendered through.

Since: 3.0.0
Focus
Focus
preRenderWebGL(renderer, child, camera)
Focus
Focus

Description:

Renders the Geometry Mask's underlying Graphics object to the OpenGL stencil buffer and enables the stencil test, which clips rendered pixels according to the mask.

Parameters:

name type description
renderer Phaser.Renderer.WebGL.WebGLRenderer

The WebGL Renderer instance to draw to.

child Phaser.GameObjects.GameObject

The Game Object being rendered.

camera Phaser.Cameras.Scene2D.Camera

The camera the Game Object is being rendered through.

Since: 3.0.0
Focus
Focus
setInvertAlpha([value])
Focus
Focus

Description:

Sets the invertAlpha property of this Geometry Mask.

Inverting the alpha essentially flips the way the mask works.

This is a WebGL only feature.

Parameters:

name type arguments Default description
value boolean <optional> true

Invert the alpha of this mask?

Returns:
Description:

This Geometry Mask

Since: 3.17.0
Focus
Focus
setShape(graphicsGeometry)
Focus
Focus

Description:

Sets a new Graphics object for the Geometry Mask.

Parameters:

name type description
graphicsGeometry Phaser.GameObjects.Graphics

The Graphics object which will be used for the Geometry Mask.

Returns:
Description:

This Geometry Mask

Since: 3.0.0
Focus
Focus