Skip to main content
Version: Phaser v4.2.1

CustomContext

The Custom Context is a game object that allows you to modify the drawing context before it is used.

The Custom Context is an extended Container Game Object. Before game objects are rendered, it clones the current DrawingContext and passes it to a callback. You can configure this callback to set options on the DrawingContext.

See the Phaser.Renderer.WebGL.DrawingContext documentation for more details on DrawingContext settings. This is an advanced rendering system and should be used carefully. You should mostly only use the setter methods on the DrawingContext object. Methods that don't begin with set are typically for internal use.

If you modify the DrawingContext to create a new framebuffer, it will not render to the canvas. It is your responsibility to use the texture from the DrawingContext. It is very inefficient to create a new framebuffer every frame, though, so you should use a DynamicTexture with a retained framebuffer instead.

Constructor

new CustomContext(scene, x, y, [children], [customContextCallback])

Parameters

nametypeoptionaldescription
scenePhaser.SceneNoThe Scene to which this Game Object belongs.
xnumberNoThe horizontal position of this Game Object in the world.
ynumberNoThe vertical position of this Game Object in the world.
childrenArray.<Phaser.GameObjects.GameObject>YesAn optional array of Game Objects to add to the Custom Context.
customContextCallbackPhaser.Types.GameObjects.CustomContext.CustomContextCallbackYesA function to be called before the custom DrawingContext is activated. If undefined, no callback will be called.

Scope: static

Extends

Phaser.GameObjects.Container

Source: src/gameobjects/customcontext/CustomContext.js#L10
Since: 4.2.0

Inherited Members​

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.ComputedSize:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.Container:

From Phaser.GameObjects.GameObject:


Public Members​

customContextCallback​

customContextCallback: Phaser.Types.GameObjects.CustomContext.CustomContextCallback, null​

Description:

A function to be called before the custom DrawingContext is activated. Set this function to modify the drawing context before it is used, or set it to null to leave it as is. If defined, the callback runs during the customContextRenderStep method.

The callback is called with one parameter: a copy of the current drawing context.

Source: src/gameobjects/customcontext/CustomContext.js#L49
Since: 4.2.0


Inherited Methods​

From Phaser.Events.EventEmitter:

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.ComputedSize:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.RenderSteps:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.Container:

From Phaser.GameObjects.GameObject:


Public Methods​

customContextRenderStep​

<instance> customContextRenderStep(renderer, gameObject, drawingContext, [parentMatrix], [renderStep], [displayList], [displayListIndex])​

Description:

The custom render step for the Custom Context. This runs before rendering the game object, allowing you to modify the drawing context before it is used.

Parameters:

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoA reference to the current active WebGL renderer.
gameObjectPhaser.GameObjects.GameObjectNoThe Game Object being rendered in this call.
drawingContextPhaser.Renderer.WebGL.DrawingContextNoThe current drawing context.
parentMatrixPhaser.GameObjects.Components.TransformMatrixYesThis transform matrix is defined if the game object is nested
renderStepnumberYesThe index of this function in the Game Object's list of render processes. Used to support multiple rendering functions.
displayListArray.<Phaser.GameObjects.GameObject>YesThe display list which is currently being rendered.
displayListIndexnumberYesThe index of the Game Object within the display list.

Source: src/gameobjects/customcontext/CustomContext.js#L73
Since: 4.2.0