Constructor
new TileLayer(pos, size, tileInfoopt, renderOrderopt, useWebGLopt)
Create a tile layer object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | World space position | ||
size | Vector2 | World space size | ||
tileInfo | TileInfo | <optional> | Default tile info for layer (used for size and texture) | |
renderOrder | number | <optional> | 0 | Objects are sorted by renderOrder |
useWebGL | boolean | <optional> | true | Should this layer use WebGL for rendering |
- Source
const tileLayer = new TileLayer(vec2(), vec2(200,100));Extends
- CanvasLayer
Members
data
Properties| Type | Description |
|---|---|
| Array.<TileLayerData> | Default tile info for layer |
- Source
isUsingWebGL
Properties| Type | Description |
|---|---|
| boolean | Is this layer using a webgl texture? |
- Source
savedRenderSettings
- Source
tileInfo
Properties| Type | Description |
|---|---|
| TileInfo | Default tile info for layer |
- Source
Methods
clearData(layerPos, redrawopt)
Clear data at a given position in the array
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
layerPos | Vector2 | Local position in array | ||
redraw | boolean | <optional> | false | Force the tile to redraw if true |
- Source
clearLayerRect(pos, size)
Clear a rectangle in layer space
| Name | Type | Description |
|---|---|---|
pos | Vector2 | position in pixel coordinates |
size | Vector2 |
- Source
drawLayerRect(pos, size, coloropt, angleopt)
Clear a rectangle in layer space
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | |||
color | Color | <optional> | WHITE | Color to modulate with |
angle | number | <optional> | 0 | Angle to rotate by |
- Source
drawLayerTile(pos, sizeopt, tileInfoopt, coloropt, angleopt, mirroropt, additiveColoropt)
Draw textured tile in layer space
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | Position in pixel coordinates | ||
size | Vector2 | <optional> | vec2(1) | Size of the tile |
tileInfo | TileInfo | <optional> | Tile info to use, untextured if undefined | |
color | Color | <optional> | WHITE | Color to modulate with |
angle | number | <optional> | 0 | Angle to rotate by |
mirror | boolean | <optional> | Is image flipped along the Y axis? | |
additiveColor | Color | <optional> | Additive color to be applied if any |
- Source
drawTileData(layerPos, clearopt)
Draw the tile at a given position in the tile layer This can be used to clear out tiles when they are destroyed Tiles can also be redrawn if inside a redrawStart/End block
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
layerPos | Vector2 | |||
clear | boolean | <optional> | true | should the old tile be cleared out |
- Source
getData(layerPos) → {TileLayerData}
Get data at a given position in the array
| Name | Type | Description |
|---|---|---|
layerPos | Vector2 | Local position in array |
- Source
- Type:
- TileLayerData
onRedraw()
Called after this layer is redrawn, does nothing by default
- Source
redraw()
Draw all the tile data to an offscreen canvas
- This may be slow if not using webgl but only needs to be done once
- Source
redrawEnd()
Call to end the redraw process
- Source
redrawStart(clearopt)
Call to start the redraw process
- This can be used to manually update parts of the level
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
clear | boolean | <optional> | false | Should it clear the canvas before drawing |
- Source
redrawTileData(layerPos, clearopt)
Draw the tile at a given position in the tile layer This can be used to clear tiles when they are destroyed For better performance use drawTileData inside a redrawStart/End block
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
layerPos | Vector2 | |||
clear | boolean | <optional> | true | should the old tile be cleared |
- Source
setData(layerPos, data, redrawopt)
Set data at a given position in the array
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
layerPos | Vector2 | Local position in array | ||
data | TileLayerData | Data to set | ||
redraw | boolean | <optional> | false | Force the tile to redraw if true |
- Source