Class: CanvasRenderer

PIXI.CanvasRenderer

The CanvasRenderer draws the scene and all its content onto a 2d canvas.

This renderer should be used for browsers that support WebGL.

This renderer should be used for browsers that do not support WebGL. Don't forget to add the view to your DOM or you will not see anything!

Renderer is composed of systems that manage specific tasks. The following systems are added by default whenever you create a renderer:

System Description
Generic Systems Systems that manage functionality that all renderer types share
PIXI.ViewSystem This manages the main view of the renderer usually a Canvas
PIXI.PluginSystem This manages plugins for the renderer
PIXI.BackgroundSystem This manages the main views background color and alpha
PIXI.StartupSystem Boots up a renderer and initiatives all the systems
PIXI.EventSystem This manages UI events.
PIXI.GenerateTextureSystem This adds the ability to generate textures from any PIXI.DisplayObject
PixiJS High-Level Systems Set of specific systems designed to work with PixiJS objects
PIXI.CanvasContextSystem This manages the canvas 2d contexts and their state
PIXI.CanvasMaskSystem This manages masking operations.
PIXI.CanvasExtract This extracts image data from a PIXI.DisplayObject
PIXI.CanvasPrepare This prepares a PIXI.DisplayObject async for rendering

The breadth of the API surface provided by the renderer is contained within these systems.

new PIXI.CanvasRenderer (options) overrides

Name Type Attributes Description
options PIXI.IRendererOptions <optional>

See PIXI.settings.RENDER_OPTIONS for defaults.

Extends

Implements

Members

_plugin PIXI.PluginSystem readonly

plugin system instance

_view PIXI.ViewSystem readonly

View system instance

autoDensity boolean

Whether CSS dimensions of canvas view should be resized to screen dimensions automatically.

background PIXI.BackgroundSystem readonly

background system instance

backgroundAlpha number Deprecated : since 7.0.0

The background color alpha. Setting this to 0 will make the canvas transparent.

backgroundColor PIXI.ColorSource Deprecated : since 7.0.0

The background color to fill if not transparent

blendModes string[] Deprecated : since 7.0.0 use `renderer.canvasContext.blendModes` instead

Tracks the blend modes useful for this renderer.

canvasContext PIXI.CanvasContextSystem readonly

Canvas context system instance

clearBeforeRender boolean

This sets if the CanvasRenderer will clear the canvas or not before the new render pass. If the scene is NOT transparent PixiJS will use a canvas sized fillRect operation every frame to set the canvas background color. If the scene is transparent PixiJS will use clearRect to clear the canvas every frame. Disable this by setting this to false. For example, if your game has a canvas filling background image you often don't need this set.

context PIXI.ICanvasRenderingContext2D Deprecated : since 7.0.0 Use `renderer.canvasContext.activeContext instead

The currently active canvas 2d context (could change with renderTextures)

height number readonly

Same as view.height, actual number of pixels in the canvas by vertical.

Default Value:
  • 600

lastObjectRendered PIXI.IRenderableObject

the last object rendered by the renderer. Useful for other plugins like interaction managers

mask PIXI.CanvasMaskSystem readonly

canvas mask system instance

maskManager PIXI.CanvasMaskSystem Deprecated : since 7.0.0 use `renderer.canvasContext.mask`

system that manages canvas masks

objectRenderer PIXI.CanvasObjectRendererSystem readonly

renderer system instance

options PIXI.IRendererOptions readonly

Options passed to the constructor.

plugins IRendererPlugins

Collection of plugins

preserveDrawingBuffer boolean Deprecated : since 7.0.0

old abstract function not used by canvas renderer

refresh boolean Deprecated : since 7.0.0

Boolean flag controlling canvas refresh.

rendererLogId string readonly

When logging Pixi to the console, this is the name we will show

Default Value:
  • "Canvas"

renderingToScreen boolean

Flag if we are rendering to the screen vs renderTexture

resolution number

The resolution / device pixel ratio of the renderer.

rootContext PIXI.ICanvasRenderingContext2D Deprecated : since 7.0.0 Use `renderer.canvasContext.rootContext instead

The root canvas 2d context that everything is drawn with.

Measurements of the screen. (0, 0, screenWidth, screenHeight). Its safe to use as filterArea or hitArea for the whole stage.

smoothProperty SmoothingEnabledProperties Deprecated : since 7.0.0 Use `renderer.canvasContext.smoothProperty` instead.

The canvas property used to set the canvas smoothing property.

startup PIXI.StartupSystem readonly

Startup system instance

textureGenerator PIXI.GenerateTextureSystem readonly

textureGenerator system instance

type number readonly

The type of the renderer. will be PIXI.RENDERER_TYPE.CANVAS

See:

useContextAlpha boolean Deprecated : since 7.0.0

old abstract function not used by canvas renderer

The canvas element that everything is drawn to.

width number readonly

Same as view.width, actual number of pixels in the canvas by horizontal.

Default Value:
  • 800

plugins object readonly

Collection of installed plugins. These are included by default in PIXI, but can be excluded by creating a custom build. Consult the README for more information about creating custom builds and excluding plugins.

Properties:
Name Type Description
accessibility PIXI.AccessibilityManager

Support tabbing interactive elements.

Methods

clear () void

Clear the canvas of renderer.

destroy (removeView) void overrides

Removes everything from the renderer and optionally removes the Canvas DOM element.

Name Type Attributes Default Description
removeView boolean <optional>
false

Removes the Canvas element from the DOM.

generateTexture (displayObject, options) PIXI.RenderTexture

Useful function that returns a texture of the display object that can then be used to create sprites This can be quite useful if your displayObject is complicated and needs to be reused multiple times.

Name Type Attributes Description
displayObject PIXI.IRenderableObject

The displayObject the object will be generated from.

options IGenerateTextureOptions <optional>

Generate texture options.

options.region PIXI.Rectangle

The region of the displayObject, that shall be rendered, if no region is specified, defaults to the local bounds of the displayObject.

options.resolution number <optional>

If not given, the renderer's resolution is used.

options.multisample PIXI.MSAA_QUALITY <optional>

If not given, the renderer's multisample is used.

Returns:
Type Description
PIXI.RenderTexture A texture of the graphics object.

invalidateBlendMode () void Deprecated`` : since 7.0.0 Use `renderer.canvasContext.invalidateBlendMode` instead.

Checks if blend mode has changed.

render (displayObject, options) void

Renders the object to its WebGL view.

Name Type Attributes Default Description
displayObject PIXI.DisplayObject

The object to be rendered.

options IRendererRenderOptions <optional>

Object to use for render options.

options.renderTexture PIXI.RenderTexture <optional>

The render texture to render to.

options.clear boolean <optional>
true

Should the canvas be cleared before the new render.

options.transform PIXI.Matrix <optional>

A transform to apply to the render texture before rendering.

options.skipUpdateTransform boolean <optional>
false

Should we skip the update transform pass?

resize (desiredScreenWidth, desiredScreenHeight) void

Resizes the canvas view to the specified width and height.

Name Type Description
desiredScreenWidth number

the desired width of the screen

desiredScreenHeight number

the desired height of the screen

setBlendMode (blendMode, readyForOuterBlend) void Deprecated`` : since 7.0.0 Use `renderer.canvasContext.setBlendMode` instead.

Sets the blend mode of the renderer.

Name Type Attributes Default Description
blendMode number

See PIXI.BLEND_MODES for valid values.

readyForOuterBlend boolean <optional>
false

Some blendModes are dangerous, they affect outer space of sprite. Pass true only if you are ready to use them.

setContextTransform (transform, roundPixels, localResolution) void Deprecated`` : since 7.0.0 - Use `renderer.canvasContext.setContextTransform` instead.

Sets matrix of context. called only from render() methods takes care about resolution

Name Type Attributes Description
transform PIXI.Matrix

world matrix of current element

roundPixels boolean <optional>

whether to round (tx,ty) coords

localResolution number <optional>

If specified, used instead of renderer.resolution for local scaling

Events

Fired after rendering finishes.

Fired before rendering starts.

Inherited Properties

From class PIXI.SystemManager

runners { [key: string]: PIXI.Runner } readonly inherited overrides

a collection of runners defined by the user

Inherited Methods

From class PIXI.SystemManager

addRunners (…runnerIds) void inherited overrides

Create a bunch of runners based of a collection of ids

Name Type Description
runnerIds string[]

the runner ids to add

addSystem (ClassRef, name) this inherited overrides

Add a new system to the renderer.

Name Type Description
ClassRef ISystemConstructor<R>

Class reference

name string

Property name for system, if not specified will use a static name property on the class itself. This name will be assigned as s property on the Renderer so make sure it doesn't collide with properties on Renderer.

Returns:
Type Description
this Return instance of renderer

emitWithCustomOptions (runner, options) void inherited overrides

A function that will run a runner and call the runners function but pass in different options to each system based on there name.

E.g. If you have two systems added called systemA and systemB you could call do the following:

system.emitWithCustomOptions(init, {
    systemA: {...optionsForA},
    systemB: {...optionsForB},
});

init would be called on system A passing optionsForA and on system B passing optionsForB.

Name Type Description
runner PIXI.Runner

the runner to target

options Record<string, unknown>

key value options for each system

Set up a system with a collection of SystemClasses and runners. Systems are attached dynamically to this class when added.

Name Type Description
config ISystemConfig<R>

the config for the system manager