TileLayers. CanvasLayer

Canvas Layer - cached off screen rendering system

  • Contains an offscreen canvas that can be rendered to
  • WebGL rendering is optional, call updateWebGL to enable/update

Constructor

new CanvasLayer(posopt, sizeopt, angleopt, renderOrderopt, canvasSizeopt, useWebGLopt)

Create a canvas layer object

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

World space position of the layer

sizeVector2<optional>

World space size of the layer

anglenumber<optional>
0

Angle the layer is rotated by

renderOrdernumber<optional>
0

Objects sorted by renderOrder

canvasSizeVector2<optional>

Default size of canvas, can be changed later

useWebGLboolean<optional>
true

Should this layer use WebGL for rendering

Example
const canvasLayer = new CanvasLayer(vec2(), vec2(200,100));

Extends

  • EngineObject

Members

canvas

Properties
TypeDescription
HTMLCanvasElement

The canvas used by this layer

context

Properties
TypeDescription
OffscreenCanvasRenderingContext2D

The 2D canvas context used by this layer

textureInfo

Properties
TypeDescription
TextureInfo

Texture info to use for this object rendering

Methods

destroy()

Destroy this canvas layer

drawRect(pos, sizeopt, coloropt, angleopt)

Draw a rectangle onto the layer canvas in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
vec2(1)
colorColor<optional>
WHITE
anglenumber<optional>

drawTile(pos, sizeopt, tileInfoopt, coloropt, angleopt, mirroropt)

Draw a tile onto the layer canvas in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
vec2(1)
tileInfoTileInfo<optional>
colorColor<optional>
WHITE
anglenumber<optional>
0
mirrorboolean<optional>
false

hasWebGL() → {boolean}

Check if this layer is using WebGL

Returns:
Type: 
boolean

updateWebGL()

Create WebGL texture if necessary and copy layer canvas to it