TileLayers. TileCollisionLayer

Tile Collision Layer - a tile layer with collision

  • adds collision data and functions to TileLayer
  • there can be multiple tile collision layers

Constructor

new TileCollisionLayer(pos, size, tileInfoopt, renderOrderopt, useWebGLopt)

Create a tile layer object

Parameters:
NameTypeAttributesDefaultDescription
posVector2

World space position

sizeVector2

World space size

tileInfoTileInfo<optional>

Tile info for layer

renderOrdernumber<optional>
0

Objects are sorted by renderOrder

useWebGLboolean<optional>
true

Should this layer use WebGL for rendering

Extends

  • TileLayer

Members

collisionData

Properties
TypeDescription
Array.<number>

The tile collision grid

Methods

clearCollisionData(layerPos)

Clear tile collision data for a given cell in the layer

Parameters:
NameTypeDescription
layerPosVector2

collisionRaycast(posStart, posEnd, objectopt, normalopt) → {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 (may have a tiny shift)

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>
vec2()
objectEngineObject<optional>
Returns:
Type: 
boolean

destroy()

Destroy this tile layer

getCollisionData(layerPos) → {number}

Get tile collision data for a given cell in the layer

Parameters:
NameTypeDescription
layerPosVector2
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(layerPos, dataopt)

Set tile collision data for a given cell in the layer

Parameters:
NameTypeAttributesDefaultDescription
layerPosVector2
datanumber<optional>
1