Constructor
new CanvasLayer(positionopt, sizeopt, angleopt, renderOrderopt, canvasSizeopt)
Create a canvas layer object
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
position | Vector2 | <optional> | World space position of the layer | |
size | Vector2 | <optional> | World space size of the layer | |
angle | number | <optional> | 0 | Angle the layer is rotated by |
renderOrder | number | <optional> | 0 | Objects sorted by renderOrder |
canvasSize | Vector2 | <optional> | Default size of canvas, can be changed later |
- Source
Example
const canvasLayer = new CanvasLayer(vec2(), vec2(200,100));
Extends
- EngineObject
Members
canvas
PropertiesType | Description |
---|---|
HTMLCanvasElement | The canvas used by this layer |
- Source
context
PropertiesType | Description |
---|---|
OffscreenCanvasRenderingContext2D | The 2D canvas context used by this layer |
- Source
refreshWebGL
PropertiesType | Description |
---|---|
boolean | True if WebGL texture needs to be refreshed |
- Source
Methods
destroy()
Destroy this canvas layer
- Source
drawCanvas2D(pos, size, angle, mirror, drawFunction)
Draw onto the layer canvas in world space (bypass WebGL)
Parameters:
Name | Type | Description |
---|---|---|
pos | Vector2 | |
size | Vector2 | |
angle | number | |
mirror | boolean | |
drawFunction | Canvas2DDrawCallback |
- Source
drawRect(pos, sizeopt, coloropt, angleopt)
Draw a rectangle onto the layer canvas in world space
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | <optional> | (1,1) | |
color | Color | <optional> | (1,1,1,1) | |
angle | number | <optional> | 0 |
- Source
drawTile(pos, sizeopt, tileInfoopt, coloropt, angleopt, mirroropt)
Draw a tile onto the layer canvas in world space
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | <optional> | (1,1) | |
tileInfo | TileInfo | <optional> | ||
color | Color | <optional> | (1,1,1,1) | |
angle | number | <optional> | 0 | |
mirror | boolean | <optional> | false |
- Source
useWebGL(enableopt, immediateopt)
Create or update the WebGL texture for this layer
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
enable | boolean | <optional> | true | enable WebGL rendering and update the texture |
immediate | boolean | <optional> | false | shoulkd the texture be updated immediately |
- Source