TileCollision

LittleJS Tile Layer System

  • Caches arrays of tiles to off screen canvas for fast rendering
  • Unlimited numbers of layers, allocates canvases as needed
  • Interfaces with EngineObject for collision
  • Collision layer is separate from visible layers
  • It is recommended to have a visible layer that matches the collision
  • Tile layers can be drawn to using their context with canvas2d
  • Drawn directly to the main canvas without using WebGL

Members

(static) tileCollision :Array

The tile collision layer grid, use setTileCollisionData and getTileCollisionData to access

Type:
  • Array

(static) tileCollisionSize :Vector2

Size of the tile collision layer 2d grid

Type:

Methods

(static) getTileCollisionData(pos) → {Number}

Get tile collision data for a given cell in the grid

Parameters:
NameTypeDescription
posVector2
Returns:
Type: 
Number

(static) initTileCollision(size)

Clear and initialize tile collision

Parameters:
NameTypeDescription
sizeVector2

width and height of tile collision 2d grid

(static) setTileCollisionData(pos, dataopt)

Set tile collision data for a given cell in the grid

Parameters:
NameTypeAttributesDefaultDescription
posVector2
dataNumber<optional>
0

(static) tileCollisionRaycast(posStart, posEnd, objectopt) → {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:
NameTypeAttributesDescription
posStartVector2
posEndVector2
objectEngineObject<optional>
Returns:
Type: 
Vector2

(static) tileCollisionTest(pos, sizeopt, objectopt) → {Boolean}

Check if collision with another object should occur

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