TileLayers. TileCollisionLayer

Tile Collision Layer - a tile layer with collision

  • adds collision data and functions to TileLayer
  • there can be multiple tile collision layers
  • its pos must be whole numbers, so its cells line up with the world grid objects land on

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, tile() by default, none when no image is loaded

renderOrdernumber<optional>
0

Objects are sorted by renderOrder

useWebGLboolean<optional>
true

Should this layer use WebGL for rendering

Extends

  • TileLayer

Members

collisionData :Array.<number>

Type:
  • Array.<number>
Properties
TypeDescription
Array.<number>

The tile collision grid

isSolid

Properties
TypeDescription
boolean

Solid layers block objects and particles, the solidOnly tests skip the others

shadowSolidOnly

Properties
TypeDescription
boolean

In the light system's shadow pass, cast only from the cells with collision, drawn as the layer shows them, so a floor in the same layer stays lit; false casts every tile

Methods

clearCollisionData(layerPos)

Clear tile collision data for a given cell in the layer

Parameters:
NameTypeDescription
layerPosVector2

collisionRaycast(posStart, posEnd, callbackObjectopt, 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
callbackObjectEngineObject | TileCollisionCallback<optional>

Callback, engine object, or undefined

normalVector2<optional>

Optional normal of the surface hit

Returns:
Type: 
Vector2 | undefined

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

Check if collision with another object should occur

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
vec2()
callbackObjectEngineObject | TileCollisionCallback<optional>

Callback, engine object, or undefined

Returns:
Type: 
boolean

destroy(immediateopt)

Destroy this tile layer

Parameters:
NameTypeAttributesDefaultDescription
immediateboolean<optional>
false

Remove it now, as EngineObject.destroy does, children included

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, the size is the layer's own, the tile data and canvas keep it

Parameters:
NameTypeDescription
sizeVector2

width and height of tile collision 2d grid

renderShadow()

Draw this layer's shadow shape: the cells with collision in the part the shadow map covers, each row of them in one draw from that part of the layer's texture, so see through pixels in a tile cast nothing; every tile when shadowSolidOnly is off, or when the layer is turned or mirrored

setCollisionData(layerPos, dataopt)

Set tile collision data for a given cell in the layer

Parameters:
NameTypeAttributesDefaultDescription
layerPosVector2
datanumber<optional>
1