LittleJS 1.28.0

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
  • A TileLayer using WebGL redraws into its texture and leaves this canvas blank, so drawing on its context only shows on a layer made with useWebGL=false (or with WebGL off); use drawLayerTile/drawLayerRect inside redrawStart/End for drawing that works both ways

Extends EngineObject

Extended by ParallaxLayer, TileLayer

Constructor

new CanvasLayer(pos, size, angle, renderOrder, canvasSize, useWebGL)engineTileLayer.js:662

Create a canvas layer object

pos Vector2 optional

World space position of the layer

size Vector2 optional

World space size of the layer

angle number optional, default 0

Angle the layer is rotated by

renderOrder number optional, default 0

Objects sorted by renderOrder

canvasSize Vector2 optional

Default size of canvas, can be changed later

useWebGL boolean optional, default true

Should this layer use WebGL for rendering

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

Members

Methods

Inherited from EngineObject

Members

canvas : OffscreenCanvasengineTileLayer.js:680

The canvas used by this layer

context : OffscreenCanvasRenderingContext2DengineTileLayer.js:678

The 2D canvas context used by this layer

Texture info to use for this object rendering

Methods

destroy(immediate)engineTileLayer.js:696

Destroy this canvas layer

immediate boolean optional, default false

Remove it now, as EngineObject.destroy does, children included

draw(pos, size, color, angle, mirror, additiveColor, screenSpace, context)engineTileLayer.js:719

Draw this canvas layer centered in world space

pos Vector2

Center in world space

size Vector2 optional

Size in world space

color Color optional

Color to modulate with

angle number optional, default 0

Angle to rotate by

mirror boolean optional, default false

If true the image is flipped left to right

additiveColor Color optional

Additive color to be applied if any

screenSpace boolean optional, default drawScreenSpace

If true the pos and size are in screen space

context CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D optional

Canvas 2D context to draw to

hasWebGL() → booleanengineTileLayer.js:741

Check if this layer is using WebGL

Create WebGL texture if necessary and copy layer canvas to it