PIXI.CanvasRenderer
class CanvasRenderer extends PIXI.AbstractRenderer
The CanvasRenderer draws the scene and all its content onto a 2d canvas.
This renderer should be used for browsers that do not support WebGL. Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything!
Constructor
new PIXI.CanvasRenderer(options: IRendererOptions) → {}
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
| options | IRendererOptions |
<optional> |
The optional renderer parameters |
|
| options.width | number |
<optional> |
800 |
the width of the screen |
| options.height | number |
<optional> |
600 |
the height of the screen |
| options.view | HTMLCanvasElement |
<optional> |
the canvas to use as a view, optional |
|
| options.useContextAlpha | boolean |
<optional> |
true |
Pass-through value for canvas' context |
| options.autoDensity | boolean |
<optional> |
false |
Resizes renderer view in CSS pixels to allow for resolutions other than 1 |
| options.antialias | boolean |
<optional> |
false |
sets antialias |
| options.resolution | number |
<optional> |
PIXI.settings.RESOLUTION |
The resolution / device pixel ratio of the renderer. |
| options.preserveDrawingBuffer | boolean |
<optional> |
false |
enables drawing buffer preservation, enable this if you need to call toDataUrl on the webgl context. |
| options.clearBeforeRender | boolean |
<optional> |
true |
This sets if the renderer will clear the canvas or not before the new render pass. |
| options.backgroundColor | number |
<optional> |
0x000000 |
The background color of the rendered area (shown if not transparent). |
| options.backgroundAlpha | number |
<optional> |
1 |
Value from 0 (fully transparent) to 1 (fully opaque). |
Summary
Properties from CanvasRenderer
| string[] |
Tracks the blend modes useful for this renderer. |
| CrossPlatformCanvasRenderingContext2D |
The currently active canvas 2d context (could change with renderTextures) |
| PIXI.CanvasMaskManager |
|
| boolean |
Boolean flag controlling canvas refresh. |
| CrossPlatformCanvasRenderingContext2D |
The root canvas 2d context that everything is drawn with. |
| SmoothingEnabledProperties |
The canvas property used to set the canvas smoothing property. |
| object |
|
Methods from CanvasRenderer
| void |
|
| this |
Adds a new system to the renderer. It does nothing in the CanvasRenderer. |
| void |
|
| void |
|
| void |
Checks if blend mode has changed. |
| void |
|
| void |
|
| void |
|
| void |
|
| void |
|
Events from CanvasRenderer
Properties inherited from AbstractRenderer
| boolean |
|
| number |
|
| number |
|
| boolean |
|
| number |
|
| object |
|
| boolean |
|
| number |
|
| PIXI.Rectangle |
Measurements of the screen. (0, 0, screenWidth, screenHeight). |
| number |
|
| boolean |
|
| HTMLCanvasElement |
|
| number |
|
| number |
|
| Array<number> |
|
| string |
|
| PIXI.DisplayObject |
|
Methods inherited from AbstractRenderer
| PIXI.RenderTexture |
|
| PIXI.RenderTexture |
|
| void |
|
Public Properties
blendModes: string[]
Tracks the blend modes useful for this renderer.
context: CrossPlatformCanvasRenderingContext2D
The currently active canvas 2d context (could change with renderTextures)
maskManager: PIXI.CanvasMaskManager
Instance of a CanvasMaskManager, handles masking when using the canvas renderer.
rootContext: CrossPlatformCanvasRenderingContext2D
The root canvas 2d context that everything is drawn with.
smoothProperty: SmoothingEnabledProperties = "imageSmoothingEnabled"
The canvas property used to set the canvas smoothing property.
plugins: object
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.
| Name | Type | Description |
|---|---|---|
| accessibility | PIXI.AccessibilityManager | Support tabbing interactive elements. |
| extract | PIXI.CanvasExtract | Extract image data from renderer. |
| interaction | PIXI.InteractionManager | Handles mouse, touch and pointer events. |
| prepare | PIXI.CanvasPrepare | Pre-render display objects. |
Public Methods
static registerPlugin(pluginName: string, ctor: ICanvasRendererPluginConstructor) → {void}
Use the PIXI.extensions.add API to register plugins.
| Name | Type | Description |
|---|---|---|
| pluginName | string |
The name of the plugin. |
| ctor | ICanvasRendererPluginConstructor |
The constructor function or class for the plugin. |
| Type | Description |
|---|---|
| void |
addSystem() → {this}
Adds a new system to the renderer. It does nothing in the CanvasRenderer.
| Type | Description |
|---|---|
| this |
clear(clearColor: string, alpha: number) → {void}
Clear the canvas of renderer.
| Name | Type | Attributes | Description |
|---|---|---|---|
| clearColor | string |
<optional> |
Clear the canvas with this color, except the canvas is transparent. |
| alpha | number |
<optional> |
Alpha to apply to the background fill color. |
| Type | Description |
|---|---|
| void |
destroy(removeView: boolean) → {void}
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. |
| Type | Description |
|---|---|
| void |
invalidateBlendMode() → {void}
Checks if blend mode has changed.
| Type | Description |
|---|---|
| void |
render(displayObject: PIXI.DisplayObject, options: IRendererRenderOptions) → {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? |
| Type | Description |
|---|---|
| void |
render(displayObject: PIXI.DisplayObject, renderTexture: PIXI.RenderTexture | PIXI.BaseRenderTexture, clear: boolean, transform: PIXI.Matrix, skipUpdateTransform: boolean) → {void}
Please use the option render arguments instead.
| Name | Type | Attributes | Description |
|---|---|---|---|
| displayObject | PIXI.DisplayObject |
The object to be rendered. |
|
| renderTexture | PIXI.RenderTexture | PIXI.BaseRenderTexture |
<optional> |
The render texture to render to. |
| clear | boolean |
<optional> |
Should the canvas be cleared before the new render. |
| transform | PIXI.Matrix |
<optional> |
A transform to apply to the render texture before rendering. |
| skipUpdateTransform | boolean |
<optional> |
Should we skip the update transform pass? |
| Type | Description |
|---|---|
| void |
resize(desiredScreenWidth: number, desiredScreenHeight: number) → {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 |
| Type | Description |
|---|---|
| void |
setBlendMode(blendMode: number, readyForOuterBlend: boolean) → {void}
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 |
| Type | Description |
|---|---|
| void |
setContextTransform(transform: PIXI.Matrix, roundPixels: boolean, localResolution: number) → {void}
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 |
| Type | Description |
|---|---|
| void |
Events
Fired after rendering finishes.
Fired before rendering starts.