ExcaliburGraphicsContext
Implemented by
Index
Properties
Methods
Properties
backgroundColor
debug
Access the debug drawing api
height
material
Gets or sets the material to be used in the current context's drawings
This allows customs shaders to be used but draw calls are no longer batched by default.
opacity
Sets the opacity of the current Graphic being drawn, default is 1
smoothing
Enable smoothed drawing (also known as anti-aliasing), by default true
snapToPixel
Snaps all drawings to the nearest pixel truncated down, by default false
tint
Sets the tint color to be multiplied by any images drawn, default is black 0xFFFFFFFF
useDrawSorting
Excalibur will automatically sort draw calls by z and priority for maximal draw performance, this can disrupt a specific desired painter order.
To force a specific draw call order, use ExcaliburGraphicsContext.z
By default useDrawSorting is true, to opt out set this to false
width
z
Set the current z context for the graphics context. Draw calls issued to the context will use this z to inform their sort order.
Note it is important to all ExcaliburGraphicsContext.save and ExcaliburGraphicsContext.restore when modifying state.
Methods
addPostProcessor
Add a post processor to the graphics context
Post processors are run in the order they were added.
Parameters
postprocessor: PostProcessor
Returns void
beginDrawLifecycle
Returns void
clear
Clears the screen with the current background color
Returns void
clearPostProcessors
Remove all post processors from the graphics context
Returns void
createMaterial
Creates and initializes the material which compiles the internal shader
Parameters
options: Omit<MaterialOptions, graphicsContext>
Returns Material
dispose
Returns void
draw
Issue a draw command to a named renderer plugin.
The renderer is looked up by name (auto-instantiating lazy renderers) and its
draw()method is called with the provided arguments. Draw calls are sorted by z-index and renderer priority before flushing.In the Canvas 2D fallback context this is a no-op.
Type parameters
- TRenderer: RendererPlugin
Parameters
rendererName: TRenderer[type]
The unique renderer type name to draw with
rest...args: Parameters<TRenderer[draw]>
Arguments forwarded to the renderer's
draw()method
Returns void
drawCircle
drawImage
Draw an image to the Excalibur Graphics context at an x and y coordinate using the images width and height
Parameters
image: HTMLImageSource
x: number
y: number
Returns void
drawLine
drawRectangle
endDrawLifecycle
Returns void
flush
Flushes the batched draw calls to the screen
Returns void
get
Look up a registered renderer plugin by its type name.
If the renderer was lazily registered, it will be instantiated and initialized on first access.
Parameters
rendererName: string
The unique renderer type name
Returns RendererPlugin | undefined
The renderer plugin, or
undefinedif not found
getTransform
Gets the current transform
Returns AffineMatrix
lazyRegister
Lazily register a custom renderer plugin with the graphics context.
The renderer factory is stored and only instantiated the first time it is requested via ExcaliburGraphicsContext.get. Use this for renderers that may not be needed in every game to avoid unnecessary initialization cost.
In the Canvas 2D fallback context this is a no-op.
Type parameters
- TRenderer: RendererPlugin
Parameters
type: TRenderer[type]
The unique renderer type name (matches RendererPlugin.type)
renderer: () => TRenderer
A factory function that creates the renderer
Returns void
multiply
Multiplies the current transform by a matrix
Parameters
m: AffineMatrix
Returns void
register
Register a custom renderer plugin with the graphics context.
The renderer is immediately initialized with the WebGL context. Use this for renderers that should always be available.
In the Canvas 2D fallback context this is a no-op.
Type parameters
Parameters
renderer: T
The renderer plugin to register
Returns void
removePostProcessor
Remove a specific post processor from the graphics context
Parameters
postprocessor: PostProcessor
Returns void
resetTransform
Resets the current transform to the identity matrix
Returns void
restore
Restore the state of the canvas from the stack
Returns void
rotate
Rotate the context about the current origin
Parameters
angle: number
Returns void
save
Save the current state of the canvas to the stack (transforms and opacity)
Returns void
scale
Scale the context by an x and y factor
Parameters
x: number
y: number
Returns void
translate
Translate the origin of the context by an x and y
Parameters
x: number
y: number
Returns void
updateViewport
Update the context with the current viewport dimensions (used in resizing)
Parameters
resolution: Resolution
Returns void
Set the background color of the graphics context, default is Color.ExcaliburBlue