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
| name | type | optional | description |
|---|---|---|---|
| scene | Phaser.Scene | No | The Scene to which this Game Object belongs. |
| x | number | No | The horizontal position of this Game Object in the world. |
| y | number | No | The vertical position of this Game Object in the world. |
| children | Array.<Phaser.GameObjects.GameObject> | Yes | An optional array of Game Objects to add to the Custom Context. |
| customContextCallback | Phaser.Types.GameObjects.CustomContext.CustomContextCallback | Yes | A function to be called before the custom DrawingContext is activated. If undefined, no callback will be called. |
Scope: static
Extends
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:
- filterCamera
- filters
- filtersAutoFocus
- filtersFocusContext
- filtersForceComposite
- maxFilterSize
- renderFilters
From Phaser.GameObjects.Components.Mask:
From Phaser.GameObjects.Components.Transform:
From Phaser.GameObjects.Components.Visible:
From Phaser.GameObjects.Container:
- displayOriginX
- displayOriginY
- exclusive
- first
- last
- length
- list
- localTransform
- maxSize
- next
- originX
- originY
- position
- previous
- scrollFactorX
- scrollFactorY
From Phaser.GameObjects.GameObject:
- active
- body
- cameraFilter
- data
- displayList
- ignoreDestroy
- input
- isDestroyed
- name
- parentContainer
- renderFlags
- scene
- state
- tabIndex
- type
- vertexRoundMode
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:
- addListener
- emit
- eventNames
- listenerCount
- listeners
- off
- on
- once
- removeAllListeners
- removeListener
- shutdown
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:
- enableFilters
- focusFilters
- focusFiltersOnCamera
- focusFiltersOverride
- renderWebGLFilters
- setFiltersAutoFocus
- setFiltersFocusContext
- setFiltersForceComposite
- setFilterSize
- setRenderFilters
- willRenderFilters
From Phaser.GameObjects.Components.Mask:
From Phaser.GameObjects.Components.RenderSteps:
From Phaser.GameObjects.Components.Transform:
- copyPosition
- getLocalPoint
- getLocalTransformMatrix
- getParentRotation
- getWorldPoint
- getWorldTransformMatrix
- setAngle
- setPosition
- setRandomPosition
- setRotation
- setScale
- setW
- setX
- setY
- setZ
From Phaser.GameObjects.Components.Visible:
From Phaser.GameObjects.Container:
- add
- addAt
- bringToTop
- count
- each
- exists
- getAll
- getAt
- getBounds
- getBoundsTransformMatrix
- getByName
- getFirst
- getIndex
- getRandom
- iterate
- moveAbove
- moveBelow
- moveDown
- moveTo
- moveUp
- onChildDestroyed
- pointToContainer
- preDestroy
- remove
- removeAll
- removeAt
- removeBetween
- replace
- reverse
- sendToBack
- setAll
- setExclusive
- setScrollFactor
- shuffle
- sort
- swap
From Phaser.GameObjects.GameObject:
- addedToScene
- addToDisplayList
- addToUpdateList
- destroy
- disableInteractive
- getData
- getDisplayList
- getIndexList
- incData
- removedFromScene
- removeFromDisplayList
- removeFromUpdateList
- removeInteractive
- setActive
- setData
- setDataEnabled
- setInteractive
- setName
- setState
- setVertexRoundMode
- toggleData
- toJSON
- update
- willRender
- willRoundVertices
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:
| name | type | optional | description |
|---|---|---|---|
| renderer | Phaser.Renderer.WebGL.WebGLRenderer | No | A reference to the current active WebGL renderer. |
| gameObject | Phaser.GameObjects.GameObject | No | The Game Object being rendered in this call. |
| drawingContext | Phaser.Renderer.WebGL.DrawingContext | No | The current drawing context. |
| parentMatrix | Phaser.GameObjects.Components.TransformMatrix | Yes | This transform matrix is defined if the game object is nested |
| renderStep | number | Yes | The index of this function in the Game Object's list of render processes. Used to support multiple rendering functions. |
| displayList | Array.<Phaser.GameObjects.GameObject> | Yes | The display list which is currently being rendered. |
| displayListIndex | number | Yes | The index of the Game Object within the display list. |
Source: src/gameobjects/customcontext/CustomContext.js#L73
Since: 4.2.0