TileLayers. CanvasLayer

Canvas Layer - cached off screen rendering system

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

Constructor

new CanvasLayer(positionopt, sizeopt, angleopt, renderOrderopt, canvasSizeopt)

Create a canvas layer object

Parameters:
NameTypeAttributesDefaultDescription
positionVector2<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

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

refreshWebGL

Properties
TypeDescription
boolean

True if WebGL texture needs to be refreshed

Methods

destroy()

Destroy this canvas layer

drawCanvas2D(pos, size, angle, mirror, drawFunction)

Draw onto the layer canvas in world space (bypass WebGL)

Parameters:
NameTypeDescription
posVector2
sizeVector2
anglenumber
mirrorboolean
drawFunctionCanvas2DDrawCallback

drawRect(pos, sizeopt, coloropt, angleopt)

Draw a rectangle onto the layer canvas in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
(1,1)
colorColor<optional>
(1,1,1,1)
anglenumber<optional>
0

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

Draw a tile onto the layer canvas in world space

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

useWebGL(enableopt, immediateopt)

Create or update the WebGL texture for this layer

Parameters:
NameTypeAttributesDefaultDescription
enableboolean<optional>
true

enable WebGL rendering and update the texture

immediateboolean<optional>
false

shoulkd the texture be updated immediately