LittleJS 1.30.1

TileLayers

TileLayer

Tile Layer - cached rendering system for tile layers

  • Tiles are drawn once into a texture, a WebGL render target, or the layer's canvas when WebGL is off or useWebGL is false, and the layer draws that as one image
  • It draws itself: whole on its first render if nothing has drawn into it, and the cells setData changed on the next render; redraw() draws the whole layer now
  • Some devices like mobile phones are limited to 4k textures, which with 16x16 tiles limits a layer to 256x256
  • Tile layers are centered on their corner, so normal levels are at (0,0)

Extends CanvasLayer

Extended by TileCollisionLayer

Constructor

new TileLayer(pos, size, tileInfo, renderOrder, useWebGL)engineTileLayer.js:1156

Create a tile layer object

pos Vector2

World space position

size Vector2

World space size

tileInfo TileInfo optional

Default tile info for layer (used for size and texture), tile() by default, none when no image is loaded

renderOrder number optional, default 0

Objects are sorted by renderOrder

useWebGL boolean optional, default true

Should this layer use WebGL for rendering

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

Members

Methods

Inherited from CanvasLayer

Inherited from EngineObject

Members

Array of tile data for the layer

debugShow : booleanengineTileLayer.js:1188

Show this layer's bounds and values when the debug overlay's Debug Tiles is on, turn it off for layers that only add noise

dirtyCells : Set<number>engineTileLayer.js:1185
tileInfo : TileInfo|undefinedengineTileLayer.js:1175

Default tile info for layer

Methods

clearData(layerPos, redraw)engineTileLayer.js:1240

Clear data at a given position in the array

layerPos Vector2

Local position in array

redraw boolean optional

True draws the cell now, false leaves it as drawn, left out draws it on the next render

drawTile(pos, size, tileInfo, color, angle, mirror)engineTileLayer.js:1375

Draw a tile onto the layer in world space, over the cells waiting to be drawn

pos Vector2
size Vector2 optional, default vec2(1)
tileInfo TileInfo optional
color Color optional, default WHITE
angle number optional
mirror boolean optional
drawTileData(layerPos, clear)engineTileLayer.js:1388

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

layerPos Vector2
clear boolean optional, default true

should the old tile be cleared out

getData(layerPos) → TileLayerData|undefinedengineTileLayer.js:1246

Get data at a given position in the array

layerPos Vector2

Local position in array

Called after this layer is redrawn, does nothing by default

Draw all the tile data to an offscreen canvas

  • This may be slow if not using webgl but only needs to be done once
redrawStart(clear)engineTileLayer.js:1352

Call to start the redraw process, after what is waiting is drawn

  • This can be used to manually update parts of the level
clear boolean optional, default false

Should it clear the canvas before drawing

redrawTileData(layerPos, clear)engineTileLayer.js:1415

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

layerPos Vector2
clear boolean optional, default true

should the old tile be cleared

setData(layerPos, data, redraw)engineTileLayer.js:1218

Set data at a given position in the array

layerPos Vector2

Local position in array

data TileLayerData

Data to set

redraw boolean optional

True draws the cell now, false leaves it as drawn, left out draws it on the next render, or now inside the layer's own redraw; when more than half the cells wait the whole layer is drawn again, clearing paint too

Create WebGL texture if necessary and copy layer canvas to it, which counts as drawn, so a picture the game drew onto the canvas is not drawn over with the tiles on the first render