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
- Source
Classes
Members
(static, constant) tileCollisionLayers :Array.<TileCollisionLayer>
Keep track of all tile layers with collision
- Array.<TileCollisionLayer>
- Source
Methods
(static) tileCollisionGetData(pos, solidOnlyopt) → {number}
Get tile collision data for a given cell in the grid
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
solidOnly | boolean | <optional> | true | Only check solid layers? |
- Source
- 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
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
posStart | Vector2 | |||
posEnd | Vector2 | |||
callbackObject | EngineObject | | <optional> | Callback, engine object, or undefined | |
normal | Vector2 | <optional> | Optional normal of the surface hit | |
solidOnly | boolean | <optional> | true | Only check solid layers? |
- Source
- 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
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | <optional> | vec2() | |
callbackObject | EngineObject | | <optional> | Callback, engine object, or undefined | |
solidOnly | boolean | <optional> | true | Only check solid layers? |
- Source
- Type:
- TileCollisionLayer
(static) tileLayersLoad(tileMapData, tileInfoopt, renderOrderopt, collisionLayeropt, drawopt) → {Array.<TileCollisionLayer>}
Load tile layers from exported data
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
tileMapData | Object | Level data from exported data | ||
tileInfo | TileInfo | <optional> | Default tile info (used for size and texture) | |
renderOrder | number | <optional> | 0 | Render order of the top layer |
collisionLayer | number | <optional> | Layer to use for collision if any | |
draw | boolean | <optional> | true | Should the layer be drawn automatically |
- Source
- Type:
- Array.<TileCollisionLayer>
Type Definitions
TileCollisionCallback(tileData, pos)
| Name | Type | Description |
|---|---|---|
tileData | number | the value of the tile at the position |
pos | Vector2 | world space position of tile where the collision occurred |
- Source