Constructor
new TileCollisionLayer(position, size, tileInfoopt, renderOrderopt, useWebGLopt)
Create a tile layer object
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
position | Vector2 | World space position | ||
size | Vector2 | World space size | ||
tileInfo | TileInfo | <optional> | Tile info for layer | |
renderOrder | number | <optional> | 0 | Objects are sorted by renderOrder |
useWebGL | boolean | <optional> | glEnable | Use accelerated WebGL rendering |
- Source
Extends
Members
additiveColor
PropertiesType | Description |
---|---|
Color | Additive color to apply when rendered |
- Overrides
- Source
angle
PropertiesType | Description |
---|---|
number | Angle to rotate the object |
- Overrides
- Source
angleDamping
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
angleDamping | number | <optional> | objectDefaultAngleDamping | How much to slow down rotation each frame (0-1) |
- Overrides
- Source
angleVelocity
PropertiesType | Description |
---|---|
number | Angular velocity of the object |
- Overrides
- Source
canvas
PropertiesType | Description |
---|---|
HTMLCanvasElement | The canvas used by this tile layer |
- Overrides
- Source
children
PropertiesType | Description |
---|---|
Array.<EngineObject> | List of children of this object |
- Overrides
- Source
clampSpeed
PropertiesType | Description |
---|---|
boolean | Limit object speed along x and y axis |
- Overrides
- Source
collideRaycast
PropertiesType | Description |
---|---|
boolean | Object collides with raycasts |
- Overrides
- Source
collideSolidObjects
PropertiesType | Description |
---|---|
boolean | Object collides with solid objects |
- Overrides
- Source
collideTiles
PropertiesType | Description |
---|---|
boolean | Object collides with the tile collision |
- Overrides
- Source
collisionData
PropertiesType | Description |
---|---|
Array.<number> | The tile collision grid |
- Source
color
PropertiesType | Description |
---|---|
Color | Color to apply when rendered |
- Overrides
- Source
context
PropertiesType | Description |
---|---|
OffscreenCanvasRenderingContext2D | The 2D canvas context used by this tile layer |
- Overrides
- Source
damping
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
damping | number | <optional> | objectDefaultDamping | How much to slow down velocity each frame (0-1) |
- Overrides
- Source
drawSize
PropertiesType | Description |
---|---|
Vector2 | Size of object used for drawing, uses size if not set |
- Overrides
- Source
friction
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
friction | number | <optional> | objectDefaultFriction | How much friction to apply when sliding (0-1) |
- Overrides
- Source
glTexture
PropertiesType | Description |
---|---|
WebGLTexture | Texture if using WebGL for this layer |
- Overrides
- Source
gravityScale
PropertiesType | Description |
---|---|
number | How much to scale gravity by for this object |
- Overrides
- Source
groundObject
PropertiesType | Description |
---|---|
EngineObject | Object we are standing on, if any |
- Overrides
- Source
isSolid
PropertiesType | Description |
---|---|
boolean | Object collides with and blocks other objects |
- Overrides
- Source
localAngle
PropertiesType | Description |
---|---|
number | Local angle if child |
- Overrides
- Source
localPos
PropertiesType | Description |
---|---|
Vector2 | Local position if child |
- Overrides
- Source
mass
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
mass | number | <optional> | objectDefaultMass | How heavy the object is, static if 0 |
- Overrides
- Source
mirror
PropertiesType | Description |
---|---|
boolean | Should it flip along y axis when rendered |
- Overrides
- Source
parent
PropertiesType | Description |
---|---|
EngineObject | Parent of object if in local space |
- Overrides
- Source
pos
PropertiesType | Description |
---|---|
Vector2 | World space position of the object |
- Overrides
- Source
renderOrder
PropertiesType | Description |
---|---|
number | Objects are sorted by render order |
- Overrides
- Source
restitution
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
restitution | number | <optional> | objectDefaultRestitution | How bouncy the object is when colliding (0-1) |
- Overrides
- Source
savedRenderSettings
- Overrides
- Source
size
PropertiesType | Description |
---|---|
Vector2 | World space width and height of the object |
- Overrides
- Source
spawnTime
PropertiesType | Description |
---|---|
number | Track when object was created |
- Overrides
- Source
tileInfo
PropertiesType | Description |
---|---|
TileInfo | Tile info to render object (undefined is untextured) |
- Overrides
- Source
velocity
PropertiesType | Description |
---|---|
Vector2 | Velocity of the object |
- Overrides
- Source
Methods
addChild(child, localPosopt, localAngleopt)
Attaches a child to this with a given local transform
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child | EngineObject | |||
localPos | Vector2 | <optional> | (0,0) | |
localAngle | number | <optional> | 0 |
- Overrides
- Source
applyAcceleration(acceleration)
Apply acceleration to this object (adjust velocity, not affected by mass)
Name | Type | Description |
---|---|---|
acceleration | Vector2 |
- Overrides
- Source
applyAngularAcceleration(acceleration)
Apply angular acceleration to this object
Name | Type | Description |
---|---|---|
acceleration | number |
- Overrides
- Source
applyForce(force)
Apply force to this object (adjust velocity, affected by mass)
Name | Type | Description |
---|---|---|
force | Vector2 |
- Overrides
- Source
collideWithObject(object) → {boolean}
Called to check if a object collision should be resolved
Name | Type | Description |
---|---|---|
object | EngineObject | the object to test against |
- Overrides
- Source
- true if the collision should be resolved
- Type:
- boolean
collideWithTile(tileData, pos) → {boolean}
Called to check if a tile collision should be resolved
Name | Type | Description |
---|---|---|
tileData | number | the value of the tile at the position |
pos | Vector2 | tile where the collision occurred |
- Overrides
- Source
- true if the collision should be resolved
- Type:
- boolean
collisionRaycast(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.
Name | Type | Attributes | Description |
---|---|---|---|
posStart | Vector2 | ||
posEnd | Vector2 | ||
object | EngineObject | <optional> |
- Source
- Type:
- Vector2
collisionTest(pos, sizeopt, objectopt) → {boolean}
Check if collision with another object should occur
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | <optional> | (0,0) | |
object | EngineObject | <optional> |
- Source
- Type:
- boolean
destroy()
Destroy this tile layer
- Overrides
- Source
drawCanvas2D(pos, size, angle, mirror, drawFunction)
Draw onto the layer canvas in world space (bypass WebGL)
- Overrides
- Source
drawRect(pos, sizeopt, coloropt, angleopt)
Draw a rectangle onto the layer canvas in world space
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | <optional> | (1,1) | |
color | Color | <optional> | (1,1,1,1) | |
angle | number | <optional> | 0 |
- Overrides
- Source
drawTile(pos, sizeopt, tileInfoopt, coloropt, angleopt, mirroropt)
Draw a tile onto the layer canvas in world space
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | <optional> | (1,1) | |
tileInfo | TileInfo | <optional> | ||
color | Color | <optional> | (1,1,1,1) | |
angle | number | <optional> | 0 | |
mirror | boolean | <optional> | false |
- Overrides
- Source
drawTileData(layerPos, clearopt)
Draw the tile at a given position in the tile grid This can be used to clear out tiles when they are destroyed Tiles can also be redrawn if inside a redrawStart/End block
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
layerPos | Vector2 | |||
clear | boolean | <optional> | true | should the old tile be cleared out |
- Overrides
- Source
getAliveTime() → {number}
How long since the object was created
- Overrides
- Source
- Type:
- number
getCollisionData(gridPos) → {number}
Get tile collision data for a given cell in the grid
Name | Type | Description |
---|---|---|
gridPos | Vector2 |
- Source
- Type:
- number
getData(layerPos) → {TileLayerData}
Get data at a given position in the array
Name | Type | Description |
---|---|---|
layerPos | Vector2 | Local position in array |
- Overrides
- Source
- Type:
- TileLayerData
getMirrorSign() → {number}
Get the direction of the mirror
- Overrides
- Source
-1 if this.mirror is true, or 1 if not mirrored
- Type:
- number
initCollision(size)
Clear and initialize tile collision to new size
Name | Type | Description |
---|---|---|
size | Vector2 | width and height of tile collision 2d grid |
- Source
localToWorld(pos)
Convert from local space to world space
Name | Type | Description |
---|---|---|
pos | Vector2 | local space point |
- Overrides
- Source
localToWorldVector(vec)
Convert from local space to world space for a vector (rotation only)
Name | Type | Description |
---|---|---|
vec | Vector2 | local space vector |
- Overrides
- Source
redraw()
Draw all the tile data to an offscreen canvas
- This may be slow in some browsers but only needs to be done once
- Overrides
- Source
redrawEnd()
Call to end the redraw process
- Overrides
- Source
redrawStart(clearopt)
Call to start the redraw process
- This can be used to manually update small parts of the level
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
clear | boolean | <optional> | false | Should it clear the canvas before drawing |
- Overrides
- Source
removeChild(child)
Removes a child from this one
Name | Type | Description |
---|---|---|
child | EngineObject |
- Overrides
- Source
render()
Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder
- Overrides
- Source
renderDebugInfo()
Render debug info for this object
- Overrides
- Source
setCollision(collideSolidObjectsopt, isSolidopt, collideTilesopt, collideRaycastopt)
Set how this object collides
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
collideSolidObjects | boolean | <optional> | true | Does it collide with solid objects? |
isSolid | boolean | <optional> | true | Does it collide with and block other objects? (expensive in large numbers) |
collideTiles | boolean | <optional> | true | Does it collide with the tile collision? |
collideRaycast | boolean | <optional> | true | Does it collide with raycasts? |
- Overrides
- Source
setCollisionData(gridPos, dataopt)
Set tile collision data for a given cell in the grid
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
gridPos | Vector2 | |||
data | number | <optional> | 1 |
- Source
setData(layerPos, data, redrawopt)
Set data at a given position in the array
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
layerPos | Vector2 | Local position in array | ||
data | TileLayerData | Data to set | ||
redraw | boolean | <optional> | false | Force the tile to redraw if true |
- Overrides
- Source
toString() → {string}
Returns string containing info about this object for debugging
- Overrides
- Source
- Type:
- string
update()
Update the object physics, called automatically by engine once each frame
- Overrides
- Source
updateTransforms()
Update the object transform, called automatically by engine even when paused
- Overrides
- Source
useWebGL(enableopt)
Create or update the WebGL texture for this layer
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
enable | boolean | <optional> | true | enable WebGL rendering and update the texture |
- Overrides
- Source
worldToLocal(pos)
Convert from world space to local space
Name | Type | Description |
---|---|---|
pos | Vector2 | world space point |
- Overrides
- Source
worldToLocalVector(vec)
Convert from world space to local space for a vector (rotation only)
Name | Type | Description |
---|---|---|
vec | Vector2 | world space vector |
- Overrides
- Source