TileLayers. TileLayer

Tile Layer - cached rendering system for tile layers

  • Each Tile layer is rendered to an off screen canvas
  • To allow dynamic modifications, layers are rendered using canvas 2d
  • Some devices like mobile phones are limited to 4k texture resolution
  • For with 16x16 tiles this limits layers to 256x256 on mobile devices
  • Tile layers are centered on their corner, so normal levels are at (0,0)

Constructor

new TileLayer(position, size, tileInfoopt, renderOrderopt)

Create a tile layer object

Parameters:
NameTypeAttributesDefaultDescription
positionVector2

World space position

sizeVector2

World space size

tileInfoTileInfo<optional>

Default tile info for layer (used for size and texture)

renderOrdernumber<optional>
0

Objects are sorted by renderOrder

Example
const tileLayer = new TileLayer(vec2(), vec2(200,100));

Extends

  • CanvasLayer

Members

savedRenderSettings

Methods

drawTileData(layerPos, clearopt)

Draw the tile at a given position in the tile grid This can be used to clear out tiles when they are destroyed Tiles can also be redrawn if inside a redrawStart/End block

Parameters:
NameTypeAttributesDefaultDescription
layerPosVector2
clearboolean<optional>
true

should the old tile be cleared out

getData(layerPos) → {TileLayerData}

Get data at a given position in the array

Parameters:
NameTypeDescription
layerPosVector2

Local position in array

Returns:
Type: 
TileLayerData

redraw()

Draw all the tile data to an offscreen canvas

  • This may be slow in some browsers but only needs to be done once

redrawEnd()

Call to end the redraw process

redrawStart(clearopt)

Call to start the redraw process

  • This can be used to manually update small parts of the level
Parameters:
NameTypeAttributesDefaultDescription
clearboolean<optional>
false

Should it clear the canvas before drawing

setData(layerPos, data, redrawopt)

Set data at a given position in the array

Parameters:
NameTypeAttributesDefaultDescription
layerPosVector2

Local position in array

dataTileLayerData

Data to set

redrawboolean<optional>
false

Force the tile to redraw if true