Two.CanvasRenderer

Extends: Two.Events

This class is used by Two when constructing with type of Two.Types.canvas. It takes Two.js' scenegraph and renders it to a <canvas />.

Constructor

ArgumentDescription
parametersThis object is inherited when constructing a new instance of Two.
parameters.domElementThe <canvas /> to draw to. If none given a new one will be constructed.
parameters.overdrawDetermines whether the canvas should clear the background or not. Defaults to true.
parameters.smoothingDetermines whether the canvas should antialias drawing. Set it to false when working with pixel art. false can lead to better performance, since it would use a cheaper interpolation algorithm.

Utils

A massive object filled with utility functions and properties to render Two.js objects to a <canvas />.

domElement

The <canvas /> associated with the Two.js scene.

ctx

Associated two dimensional context to render on the <canvas />.

overdraw

Determines whether the canvas clears the background each draw call.

scene

The root group of the scenegraph.

setSize

Triggers:

  • event:resize
ArgumentDescription
widthThe new width of the renderer.
heightThe new height of the renderer.
ratioThe new pixel ratio (pixel density) of the renderer. Defaults to calculate the pixel density of the user's screen.

Change the size of the renderer.

render

Render the current scene to the <canvas />.