Constructor
new CanvasLayer(posopt, sizeopt, angleopt, renderOrderopt, canvasSizeopt, useWebGLopt)
Create a canvas layer object
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | 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 | |
useWebGL | boolean | <optional> | true | Should this layer use WebGL for rendering |
- Source
Example
const canvasLayer = new CanvasLayer(vec2(), vec2(200,100));Extends
- EngineObject
Members
canvas
Properties| Type | Description |
|---|---|
| HTMLCanvasElement | The canvas used by this layer |
- Source
context
Properties| Type | Description |
|---|---|
| OffscreenCanvasRenderingContext2D | The 2D canvas context used by this layer |
- Source
textureInfo
Properties| Type | Description |
|---|---|
| TextureInfo | Texture info to use for this object rendering |
- Source
Methods
destroy()
Destroy this canvas layer
- 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> | vec2(1) | |
color | Color | <optional> | WHITE | |
angle | number | <optional> |
- 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> | vec2(1) | |
tileInfo | TileInfo | <optional> | ||
color | Color | <optional> | WHITE | |
angle | number | <optional> | 0 | |
mirror | boolean | <optional> | false |
- Source
hasWebGL() → {boolean}
Check if this layer is using WebGL
- Source
Returns:
- Type:
- boolean
updateWebGL()
Create WebGL texture if necessary and copy layer canvas to it
- Source