TileLayers. TileCollisionLayer

Tile Collision Layer - a tile layer with collision

  • adds collision data and functions to TileLayer
  • there can be multiple tile collision layers
  • tile collision layers should not overlap each other

Constructor

new TileCollisionLayer(position, size, tileInfoopt, renderOrderopt)

Create a tile layer object

Parameters:
NameTypeAttributesDefaultDescription
positionVector2

World space position

sizeVector2

World space size

tileInfoTileInfo<optional>

Tile info for layer

renderOrdernumber<optional>
0

Objects are sorted by renderOrder

Extends

  • TileLayer

Members

collisionData

Properties
TypeDescription
Array.<number>

The tile collision grid

Methods

collisionRaycast(posStart, posEnd, objectopt, normalopt) → {Vector2|undefined}

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

Parameters:
NameTypeAttributesDescription
posStartVector2
posEndVector2
objectEngineObject<optional>

An object or undefined for generic test

normalVector2<optional>

Optional normal of the surface hit

Returns:
Type: 
Vector2 | undefined

collisionTest(pos, sizeopt, objectopt) → {boolean}

Check if collision with another object should occur

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

destroy()

Destroy this tile layer

getCollisionData(gridPos) → {number}

Get tile collision data for a given cell in the grid

Parameters:
NameTypeDescription
gridPosVector2
Returns:
Type: 
number

initCollision(size)

Clear and initialize tile collision to new size

Parameters:
NameTypeDescription
sizeVector2

width and height of tile collision 2d grid

setCollisionData(gridPos, dataopt)

Set tile collision data for a given cell in the grid

Parameters:
NameTypeAttributesDefaultDescription
gridPosVector2
datanumber<optional>
1