Create a canvas layer object
pos Vector2 optionalWorld space position of the layer
size Vector2 optionalWorld space size of the layer
angle number optional, default 0Angle the layer is rotated by
renderOrder number optional, default 0Objects sorted by renderOrder
canvasSize Vector2 optionalDefault size of canvas, can be changed later
useWebGL boolean optional, default trueShould this layer use WebGL for rendering
const canvasLayer = new CanvasLayer(vec2(), vec2(200,100), 0, 0, vec2(400,200)); // 2 pixels a unit both ways
The canvas used by this layer
The 2D canvas context used by this layer
Is this layer drawing into its WebGL texture, set by redrawStart
Texture info to use for this object rendering
Clear a rectangle in layer space
pos Vector2position in pixel coordinates
size Vector2
Destroy this canvas layer
immediate boolean optional, default falseRemove it now, as EngineObject.destroy does, children included
Draw this canvas layer centered in world space
pos Vector2Center in world space
size Vector2 optionalSize in world space
color Color optionalColor to modulate with
angle number optional, default 0Angle to rotate by
mirror boolean optional, default falseIf true the image is flipped left to right
additiveColor Color optionalAdditive color to be applied if any
screenSpace boolean optional, default drawScreenSpaceIf true the pos and size are in screen space
context CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D optionalCanvas 2D context to draw to
Draw a rectangle in layer space
pos Vector2size Vector2color Color optional, default WHITEColor to modulate with
angle number optional, default 0Angle to rotate by
Draw textured tile in layer space
pos Vector2Position in pixel coordinates
size Vector2 optional, default vec2(1)Size of the tile
tileInfo TileInfo optionalTile info to use, untextured if undefined
color Color optional, default WHITEColor to modulate with
angle number optional, default 0Angle to rotate by
mirror boolean optionalIs the image flipped left to right?
additiveColor Color optionalAdditive color to be applied if any
Draw a rectangle onto the layer in world space, where it shows in the world
- Like drawTile, many go between one redrawStart() and redrawEnd()
pos Vector2size Vector2 optional, default vec2(1)color Color optional, default WHITEangle number optional
Draw a tile onto the layer in world space, where it shows in the world, whatever the layer's place, turn and
mirror
- Each call outside redrawStart and redrawEnd switches to the layer and back, a draw of its own; many in one
frame, like a splat for each particle, are drawn between one redrawStart() and redrawEnd()
pos Vector2size Vector2 optional, default vec2(1)tileInfo TileInfo optionalcolor Color optional, default WHITEangle number optional, default 0mirror boolean optional, default false
Check if this layer is using WebGL
Called when the WebGL context comes back after it was lost, does nothing by default
- What was drawn into the layer's texture is gone with the context, draw it again here to keep it; a
TileLayer draws its tiles again on its own before this
Call to end the redraw process
Call to start the redraw process, drawing into the layer until redrawEnd
clear boolean optional, default falseShould it clear the canvas before drawing
Create WebGL texture if necessary and copy layer canvas to it