Foundation.CanvasRenderer2D

The actor responsible for rendering the game scene. This type uses 2D canvas contexts for rendering. A unique canvas context will be created for each layer in the game's layer list.


Example

// Create a default game prefab
var game = Foundation.Game.createDefaultPrefab();

// Set the renderer background color
game['renderer'].setBackgroundColor(Foundation.Color.black);


Implementation Details

Reference paths

  • '/foundation/_digest.ts'
  • '/foundation/core/actors/_digest.ts'
  • '/foundation/core/actors/CanvasRenderer2D.ts'

Extends

This type extends:

An update() call will render the current state of the game.

equals check is not overridden from the base.

Implements

This type does not implement any interfaces (except those in the base).


antiAliasing: boolean

  • Setter only. Turns image smoothing on / off for all current layers.
  • If new layers are added, this will have to be called again to apply the setting.
  • Available: 0.7.1+

Constructors

(layers: OrderedUpdateDictionary<Layer>, camera: Camera, container: HTMLElement)

  • layers: An OrderedUpdateDictionary of Layer objects to render
  • camera: The game's camera instance
  • container: The game's HTML container element

Instance Methods

setBackgroundColor(color: Color): void

  • Set the background color of the HTML container. Here for convenience, and simple sets the background color css property on the element.
  • For more flexibility, set the HTML container's background css manually.

captureFrame(renderT?: CanvasRenderingContext2D, callback?: Function): void

  • Used to capture a "screen shot" of the currently rendered frame.
  • If a 2D rendering context is passed, it will be used to render the frame. If not, a new canvas element will be created.
  • If a callback function is passed, the rendered canvas element will be passed to the callback. If not, a window.open call will be made with the canvas's toDataURL result (This will most likely be blocked by default in a browser--look for blocked notifications).