API Docs for: 2.2.1
Show:

CanvasRenderer Class

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 :)

Constructor

CanvasRenderer

(
  • [width=800]
  • [height=600]
  • [options]
)

Parameters:

  • [width=800] Float optional

    the width of the canvas view

  • [height=600] Float optional

    the height of the canvas view

  • [options] Object optional

    The optional renderer parameters

    • [view] HTMLCanvasElement optional

      the canvas to use as a view, optional

    • [transparent=false] Bool optional

      If the render view is transparent, default false

    • [resolution=1] Float optional

      the resolution of the renderer retina would be 2

    • [clearBeforeRender=true] Bool optional

      This sets if the CanvasRenderer will clear the canvas or not before the new render pass.

Methods

render

(
  • stage
)

Renders the stage to its canvas view

Parameters:

  • stage Stage

    the Stage element to be rendered

resize

(
  • width
  • height
)

Resizes the canvas view to the specified width and height

Parameters:

  • width Float

    the new width of the canvas view

  • height Float

    the new height of the canvas view

Properties

clearBeforeRender

Bool

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.

context

CanvasRenderingContext2D 2d Context

The canvas 2d context that everything is drawn with

height

Float

The height of the canvas view

Default: 600

maskManager

CanvasMaskManager

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

refresh

Bool

Boolean flag controlling canvas refresh.

renderSession

Dynamic

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

resolution

Float

The resolution of the canvas

Default: 1

transparent

Bool

Whether the render view is transparent

view

CanvasElement

The canvas element that everything is drawn to

width

Float

The width of the canvas view

Default: 800