TileLayers

LittleJS Tile Layer System

  • Caches arrays of tiles to off screen canvas for fast rendering
  • Unlimited numbers of layers, allocates canvases as needed
  • Tile layers can be drawn to using their context with canvas2d
  • Tile layers can also have collision with EngineObjects

Classes

CanvasLayer
TileCollisionLayer
TileLayer
TileLayerData

Members

(static, constant) tileCollisionLayers :Array.<TileCollisionLayer>

Keep track of all tile layers with collision

Type:
  • Array.<TileCollisionLayer>

Methods

(static) tileCollisionGetData(pos) → {number}

Get tile collision data for a given cell in the grid

Parameters:
NameTypeDescription
posVector2
Returns:
Type: 
number

(static) tileCollisionRaycast(posStart, posEnd, objectopt, normalopt, solidOnlyopt) → {Vector2|undefined}

Return the exact position of the boudnary of first tile hit, undefined if nothing was hit.

Parameters:
NameTypeAttributesDefaultDescription
posStartVector2
posEndVector2
objectEngineObject<optional>

An object or undefined for generic test

normalVector2<optional>

Optional normal of the surface hit

solidOnlyboolean<optional>
true

Only check solid layers if true

Returns:
  • position of the center of the tile hit or undefined if no hit
Type: 
Vector2 | undefined

(static) tileCollisionTest(pos, sizeopt, objectopt, solidOnlyopt) → {TileCollisionLayer}

Check if a tile layer collides with another object

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
(0,0)
objectEngineObject<optional>

An object or undefined for generic test

solidOnlyboolean<optional>
true

Only check solid layers if true

Returns:
Type: 
TileCollisionLayer

(static) tileLayersLoad(tileMapData, tileInfoopt, renderOrderopt, collisionLayeropt, drawopt) → {Array.<TileCollisionLayer>}

Load tile layers from exported data

Parameters:
NameTypeAttributesDefaultDescription
tileMapDataObject

Level data from exported data

tileInfoTileInfo<optional>

Default tile info (used for size and texture)

renderOrdernumber<optional>
0

Render order of the top layer

collisionLayernumber<optional>

Layer to use for collision if any

drawboolean<optional>
true

Should the layer be drawn automatically

Returns:
Type: 
Array.<TileCollisionLayer>

Type Definitions

Canvas2DDrawCallback(context)

Parameters:
NameTypeDescription
contextCanvasRenderingContext2D | OffscreenCanvasRenderingContext2D