Constructor
# new TileLayer(positionopt, sizeopt, tileSizeopt, scaleopt, renderOrderopt)
Create a tile layer object
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
position |
Vector2 |
<optional> |
new Vector2(0,0) | World space position |
size |
Vector2 |
<optional> |
objectDefaultSize | World space size |
tileSize |
Vector2 |
<optional> |
tileSizeDefault | Size of tiles in source pixels |
scale |
Vector2 |
<optional> |
new Vector2(1,1) | How much to scale this layer when rendered |
renderOrder |
Number |
<optional> |
0 | Objects sorted by renderOrder before being rendered |
- Source:
Example
// create tile collision and visible tile layer
initTileCollision(vec2(200,100));
const tileLayer = new TileLayer();
Extends
Members
# additiveColor
Properties
Type | Description |
---|---|
Color | Additive color to apply when rendered |
- Overrides:
- Source:
# angle
Properties
Type | Description |
---|---|
Number | Angle to rotate the object |
- Overrides:
- Source:
# angleDamping
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
angleDamping |
Number |
<optional> |
objectDefaultAngleDamping | How much to slow down rotation each frame (0-1) |
- Overrides:
- Source:
# canvas
Properties
Type | Description |
---|---|
HTMLCanvasElement | The canvas used by this tile layer |
- Source:
# color
Properties
Type | Description |
---|---|
Color | Color to apply when rendered |
- Overrides:
- Source:
# context
Properties
Type | Description |
---|---|
CanvasRenderingContext2D | The 2D canvas context used by this tile layer |
- Source:
# damping
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
damping |
Number |
<optional> |
objectDefaultDamping | How much to slow down velocity each frame (0-1) |
- Overrides:
- Source:
# drawSize
Properties
Type | Description |
---|---|
Vector2 | Size of object used for drawing, uses size if not set |
- Overrides:
- Source:
# elasticity
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
elasticity |
Number |
<optional> |
objectDefaultElasticity | How bouncy the object is when colliding (0-1) |
- Overrides:
- Source:
# friction
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
friction |
Number |
<optional> |
objectDefaultFriction | How much friction to apply when sliding (0-1) |
- Overrides:
- Source:
# gravityScale
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
gravityScale |
Number |
<optional> |
1 | How much to scale gravity by for this object |
- Overrides:
- Source:
# isOverlay
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
isOverlay |
Boolean |
<optional> |
0 | If true this layer will render to overlay canvas and appear above all objects |
- Source:
# mass
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
mass |
Number |
<optional> |
objectDefaultMass | How heavy the object is |
- Overrides:
- Source:
# pos
Properties
Type | Description |
---|---|
Vector2 | World space position of the object |
- Overrides:
- Source:
# renderOrder
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
renderOrder |
Number |
<optional> |
0 | Objects are sorted by render order |
- Overrides:
- Source:
# scale
Properties
Type | Description |
---|---|
Vector2 | How much to scale this layer when rendered |
- Source:
# size
Properties
Type | Description |
---|---|
Vector2 | World space width and height of the object |
- Overrides:
- Source:
# tileIndex
Properties
Type | Description |
---|---|
Number | Tile to use to render object, untextured if -1 |
- Overrides:
- Source:
# tileSize
Properties
Type | Description |
---|---|
Vector2 | Size of tile in source pixels |
- Overrides:
- Source:
Methods
# addChild(child, localPosopt, localAngleopt)
Attaches a child to this with a given local transform
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
EngineObject | |||
localPos |
Vector2 |
<optional> |
new Vector2 | |
localAngle |
Number |
<optional> |
0 |
- Overrides:
- Source:
# applyAcceleration(acceleration)
Apply acceleration to this object (adjust velocity, not affected by mass)
Parameters:
Name | Type | Description |
---|---|---|
acceleration |
Vector2 |
- Overrides:
- Source:
# applyForce(force)
Apply force to this object (adjust velocity, affected by mass)
Parameters:
Name | Type | Description |
---|---|---|
force |
Vector2 |
- Overrides:
- Source:
# collideWithObject(object) → {Boolean}
Called to check if a tile raycast hit
Parameters:
Name | Type | Description |
---|---|---|
object |
EngineObject | the object to test against |
- Overrides:
- Source:
Returns:
true if the collision should be resolved
- Type
- Boolean
# collideWithTile(tileData, pos) → {Boolean}
Called to check if a tile collision should be resolved
Parameters:
Name | Type | Description |
---|---|---|
tileData |
Number | the value of the tile at the position |
pos |
Vector2 | tile where the collision occured |
- Overrides:
- Source:
Returns:
true if the collision should be resolved
- Type
- Boolean
# collideWithTileRaycast(tileData, pos) → {Boolean}
Called to check if a tile raycast hit
Parameters:
Name | Type | Description |
---|---|---|
tileData |
Number | the value of the tile at the position |
pos |
Vector2 | tile where the raycast is |
- Overrides:
- Source:
Returns:
true if the raycast should hit
- Type
- Boolean
# destroy()
Destroy this tile layer
- Overrides:
- Source:
# drawAllTileData()
Draw all the tiles in this layer
- Source:
# drawCanvas2D(pos, size, angle, mirror, drawFunction)
Draw directly to the 2d canvas in world space (bipass webgl)
Parameters:
Name | Type | Description |
---|---|---|
pos |
Vector2 | |
size |
Vector2 | |
angle |
Number | |
mirror |
Boolean | |
drawFunction |
function |
- Source:
# drawRect(pos, sizeopt, coloropt, angleopt)
Draw a rectangle directly onto the layer canvas
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos |
Vector2 | |||
size |
Vector2 |
<optional> |
new Vector2(1,1) | |
color |
Color |
<optional> |
new Color(1,1,1) | |
angle |
Number |
<optional> |
0 |
- Source:
# drawTile(pos, sizeopt, tileIndexopt, tileSizeopt, coloropt, angleopt, mirroropt)
Draw a tile directly onto the layer canvas
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos |
Vector2 | |||
size |
Vector2 |
<optional> |
new Vector2(1,1) | |
tileIndex |
Number |
<optional> |
-1 | |
tileSize |
Vector2 |
<optional> |
tileSizeDefault | |
color |
Color |
<optional> |
new Color(1,1,1) | |
angle |
Number |
<optional> |
0 | |
mirror |
Boolean |
<optional> |
0 |
- Source:
# drawTileData(layerPos)
Draw the tile at a given position
Parameters:
Name | Type | Description |
---|---|---|
layerPos |
Vector2 |
- Source:
# getAliveTime() → {Number}
How long since the object was created
- Overrides:
- Source:
Returns:
- Type
- Number
# getData(layerPos) → {TileLayerData}
Get data at a given position in the array
Parameters:
Name | Type | Description |
---|---|---|
layerPos |
Vector2 | Local position in array |
- Source:
Returns:
- Type
- TileLayerData
# getMirrorSign() → {Number}
Get the direction of the mirror
- Overrides:
- Source:
Returns:
-1 if this.mirror is true, or 1 if not mirrored
- Type
- Number
# redraw()
Draw all the tile data to an offscreen canvas using webgl if possible
- Source:
# redrawEnd()
Call to end the redraw process
- Source:
# redrawStart(clearopt)
Call to start the redraw process
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
clear |
Boolean |
<optional> |
1 | Should it clear the canvas before drawing |
- Source:
# removeChild(child)
Removes a child from this one
Parameters:
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:
# setCollision(collideSolidObjectsopt, isSolidopt, collideTilesopt)
Set how this object collides
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
collideSolidObjects |
boolean |
<optional> |
0 | Does it collide with solid objects |
isSolid |
boolean |
<optional> |
0 | Does it collide with and block other objects (expensive in large numbers) |
collideTiles |
boolean |
<optional> |
1 | Does it collide with the tile collision |
- Overrides:
- Source:
# setData(position, data, redrawopt)
Set data at a given position in the array
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
position |
Vector2 | Local position in array | ||
data |
TileLayerData | Data to set | ||
redraw |
Boolean |
<optional> |
0 | Force the tile to redraw if true |
- Source:
# update()
Update the object transform and physics, called automatically by engine once each frame
- Overrides:
- Source: