TileCollision

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

Members

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

Keep track of all tile layers with collision

Type:

Methods

(static) tileCollisionGetData(pos) → {number}

Get tile collision data for a given cell in the grid

Parameters:
NameTypeDescription
posVector2
Returns:
Type: 
number

(static) tileCollisionLoad(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>

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

Return the center of first tile hit, undefined if nothing was hit. This does not return the exact intersection, but the center of the tile hit.

Parameters:
NameTypeAttributesDefaultDescription
posStartVector2
posEndVector2
objectEngineObject<optional>

An object or undefined for generic test

solidOnlyboolean<optional>
true

Only check solid layers if true

Returns:
Type: 
Vector2

(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