TileLayers

LittleJS Tile Layer System

  • Renders large tile-based levels efficiently using cached canvases
  • Unlimited tile layers with automatic canvas allocation
  • Layers support both rendering and collision detection
  • Direct canvas2d drawing access for custom tile rendering
  • TileLayer for rendering, TileCollisionLayer for physics
  • Collision callbacks for tile interactions with objects
  • Optimized raycast support for tile-based physics
  • Integration with Box2D physics via Box2DTileLayer plugin

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, solidOnlyopt) → {number}

Get tile collision data for a given cell in the grid

Parameters:
NameTypeAttributesDefaultDescription
posVector2
solidOnlyboolean<optional>
true

Only check solid layers?

Returns:
Type: 
number

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

Return the exact position of the boundary of first tile hit, undefined if nothing was hit. The point will be inside the colliding tile if it hits

Parameters:
NameTypeAttributesDefaultDescription
posStartVector2
posEndVector2
callbackObjectEngineObject | TileCollisionCallback<optional>

Callback, engine object, or undefined

normalVector2<optional>

Optional normal of the surface hit

solidOnlyboolean<optional>
true

Only check solid layers?

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

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

Check if a tile layer collides with another object

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
vec2()
callbackObjectEngineObject | TileCollisionCallback<optional>

Callback, engine object, or undefined

solidOnlyboolean<optional>
true

Only check solid layers?

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

TileCollisionCallback(tileData, pos)

Parameters:
NameTypeDescription
tileDatanumber

the value of the tile at the position

posVector2

world space position of tile where the collision occurred