LittleJS 1.28.0

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

Extends TileLayer

Constructor

new TileCollisionLayer(pos, size, tileInfo, renderOrder, useWebGL)engineTileLayer.js:1098

Create a tile layer object

pos Vector2

World space position

size Vector2

World space size

tileInfo TileInfo optional

Tile info for layer, tile() by default, none when no image is loaded

renderOrder number optional, default 0

Objects are sorted by renderOrder

useWebGL boolean optional, default true

Should this layer use WebGL for rendering

Members

Methods

Inherited from TileLayer

Inherited from CanvasLayer

Inherited from EngineObject

Members

collisionData : Array<number>engineTileLayer.js:1113

The tile collision grid

isSolid : booleanengineTileLayer.js:1120

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

oneWayTiles : Map<number, Vector2>engineTileLayer.js:1127

The tiles set one way, by tile index, and the way each can be passed through, see setOneWay

shadowSolidOnly : booleanengineTileLayer.js:1123

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)engineTileLayer.js:1216

Clear tile collision data for a given cell in the layer

layerPos Vector2
collisionRaycast(posStart, posEnd, callbackObject, normal) → Vector2|undefinedengineTileLayer.js:1276

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)

posStart Vector2
posEnd Vector2
callbackObject EngineObject|TileCollisionCallback optional

Callback, engine object, or undefined

normal Vector2 optional

Optional normal of the surface hit

collisionTest(pos, size, callbackObject) → booleanengineTileLayer.js:1234

Check if collision with another object should occur

pos Vector2
size Vector2 optional, default vec2()
callbackObject EngineObject|TileCollisionCallback optional

Callback, engine object, or undefined

destroy(immediate)engineTileLayer.js:1183

Destroy this tile layer

immediate boolean optional, default false

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

getCollisionData(layerPos) → numberengineTileLayer.js:1222

Get tile collision data for a given cell in the layer

layerPos Vector2
initCollision(size)engineTileLayer.js:1196

Clear and initialize tile collision, the size is the layer's own, the tile data and canvas keep it

size Vector2

width and height of tile collision 2d grid

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, data)engineTileLayer.js:1207

Set tile collision data for a given cell in the layer

layerPos Vector2
data number optional, default 1
setOneWay(tile, direction)engineTileLayer.js:1143

Make the cells that draw a tile one way, like a platform jumped up through and landed on: an object, a particle or a ray passes through moving that way, and the tile blocks only what was wholly on its far side before it moved, the side it is passed toward; turned and mirrored as each cell's tile is, so a platform turned a quarter is one way to the side

  • A moving object is not stopped or asked through collideWithTile until the tile would block it, so a collideWithTile that returns false lets it drop through
  • tileCollisionTest with an object goes by the object's pos, a raycast by its start, and a test with no object or with a callback finds every one way tile solid
tile number

The tile index, as tile() and TileLayerData take it

direction Vector2 optional

Up, down, left or right, the way it can be passed through: vec2(0, 1), the default, is a platform landed on from above; layer.oneWayTiles.delete(tile) makes the tile solid again

layer.setOneWay(5); // tile 5 is a platform, jumped up through and stood on