Navigation
These archived docs are for Phaser 2.2.2 Phaser 3 docs can be found on newdocs.phaser.io.
Phaser CE docs can be found on the Phaser CE Documentation site.

Constructor

PIXI. CanvasRenderer

new CanvasRenderer(width, height, options)

The CanvasRenderer draws the Stage 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 :)

Parameters
Name Type Argument Default Description
width Number <optional>
800

the width of the canvas view

height Number <optional>
600

the height of the canvas view

options Object <optional>

The optional renderer parameters

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 5

Public Properties

autoResize : boolean

Whether the render view should be resized automatically

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 76

CanvasMaskManager : PIXI.CanvasMaskManager

Instance of a PIXI.CanvasMaskManager, handles masking when using the canvas renderer

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 140

clearBeforeRender : boolean

This sets if the CanvasRenderer will clear the canvas or not before the new render pass. If the Stage is NOT transparent Pixi will use a canvas sized fillRect operation every frame to set the canvas background color. If the Stage is transparent Pixi 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.

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 56

context :CanvasRenderingContext2D

The canvas 2d context that everything is drawn with

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 114

count : number

Internal var.

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 132

height : number

The height of the canvas view

Default Value
  • 600
Source code: pixi/renderers/canvas/CanvasRenderer.js, line 94

refresh : boolean

Boolean flag controlling canvas refresh.

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 121

renderSession : Object

The render session is just a bunch of parameter used for rendering

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 147

resolution : number

The resolution of the canvas.

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 48

transparent : boolean

Whether the render view is transparent

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 68

type : number

The renderer type.

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 40

view :HTMLCanvasElement

The canvas element that everything is drawn to.

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 106

width : number

The width of the canvas view

Default Value
  • 800
Source code: pixi/renderers/canvas/CanvasRenderer.js, line 85

Public Methods

destroy(removeView)

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

Parameters
Name Type Argument Default Description
removeView Boolean <optional>
true

Removes the Canvas element from the DOM.

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 233

render(stage)

Renders the Stage to this canvas view

Parameters
Name Type Description
stage PIXI.Stage

the Stage element to be rendered

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 184

resize(width, height)

Resizes the canvas view to the specified width and height

Parameters
Name Type Description
width Number

the new width of the canvas view

height Number

the new height of the canvas view

Source code: pixi/renderers/canvas/CanvasRenderer.js, line 255