Constructor
new EngineObject(positionopt, sizeopt, tileIndexopt, tileSizeopt, angleopt, coloropt, renderOrderopt)
Create an engine object and adds it to the list of objects
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
position | Vector2 | <optional> | Vector2() | World space position of the object |
size | Vector2 | <optional> | Vector2(1,1) | World space size of the object |
tileIndex | Number | <optional> | -1 | Tile to use to render object (-1 is untextured) |
tileSize | Vector2 | <optional> | tileSizeDefault | Size of tile in source pixels |
angle | Number | <optional> | 0 | Angle the object is rotated by |
color | Color | <optional> | Color() | Color to apply to tile when rendered |
renderOrder | Number | <optional> | 0 | Objects sorted by renderOrder before being rendered |
- Source
// create an engine object, normally you would first extend the class with your own
const pos = vec2(2,3);
const object = new EngineObject(pos);
Members
additiveColor
PropertiesType | Description |
---|---|
Color | Additive color to apply when rendered |
- Source
angle
PropertiesType | Description |
---|---|
Number | Angle to rotate the object |
- Source
angleDamping
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
angleDamping | Number | <optional> | objectDefaultAngleDamping | How much to slow down rotation each frame (0-1) |
- Source
angleVelocity
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
angleVelocity | Number | <optional> | 0 | Angular velocity of the object |
- Source
color
PropertiesType | Description |
---|---|
Color | Color to apply when rendered |
- Source
damping
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
damping | Number | <optional> | objectDefaultDamping | How much to slow down velocity each frame (0-1) |
- Source
drawSize
PropertiesType | Description |
---|---|
Vector2 | Size of object used for drawing, uses size if not set |
- Source
elasticity
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
elasticity | Number | <optional> | objectDefaultElasticity | How bouncy the object is when colliding (0-1) |
- Source
friction
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
friction | Number | <optional> | objectDefaultFriction | How much friction to apply when sliding (0-1) |
- Source
gravityScale
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
gravityScale | Number | <optional> | 1 | How much to scale gravity by for this object |
- Source
mass
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
mass | Number | <optional> | objectDefaultMass | How heavy the object is, static if 0 |
- Source
pos
PropertiesType | Description |
---|---|
Vector2 | World space position of the object |
- Source
renderOrder
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
renderOrder | Number | <optional> | 0 | Objects are sorted by render order |
- Source
size
PropertiesType | Description |
---|---|
Vector2 | World space width and height of the object |
- Source
tileIndex
PropertiesType | Description |
---|---|
Number | Tile to use to render object (-1 is untextured) |
- Source
tileSize
PropertiesType | Description |
---|---|
Vector2 | Size of tile in source pixels |
- Source
velocity
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
velocity | Vector2 | <optional> | Vector2() | Velocity of the object |
- 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> | Vector2() | |
localAngle | Number | <optional> | 0 |
- Source
applyAcceleration(acceleration)
Apply acceleration to this object (adjust velocity, not affected by mass)
Name | Type | Description |
---|---|---|
acceleration | Vector2 |
- Source
applyForce(force)
Apply force to this object (adjust velocity, affected by mass)
Name | Type | Description |
---|---|---|
force | Vector2 |
- Source
collideWithObject(object) → {Boolean}
Called to check if a object collision should be resolved
Name | Type | Description |
---|---|---|
object | EngineObject | the object to test against |
- 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 occured |
- Source
- true if the collision should be resolved
- Type:
- Boolean
collideWithTileRaycast(tileData, pos) → {Boolean}
Called to check if a tile raycast hit
Name | Type | Description |
---|---|---|
tileData | Number | the value of the tile at the position |
pos | Vector2 | tile where the raycast is |
- Source
- true if the raycast should hit
- Type:
- Boolean
destroy()
Destroy this object, destroy it's children, detach it's parent, and mark it for removal
- Source
getAliveTime() → {Number}
How long since the object was created
- Source
- Type:
- Number
getMirrorSign() → {Number}
Get the direction of the mirror
- Source
-1 if this.mirror is true, or 1 if not mirrored
- Type:
- Number
removeChild(child)
Removes a child from this one
Name | Type | Description |
---|---|---|
child | EngineObject |
- Source
render()
Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder
- Source
setCollision(collideSolidObjectsopt, isSolidopt, collideTilesopt)
Set how this object collides
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
collideSolidObjects | Boolean | <optional> | 1 | Does it collide with solid objects |
isSolid | Boolean | <optional> | 1 | Does it collide with and block other objects (expensive in large numbers) |
collideTiles | Boolean | <optional> | 1 | Does it collide with the tile collision |
- Source
toString() → {String}
Returns string containg info about this object for debugging
- Source
- Type:
- String
update()
Update the object transform and physics, called automatically by engine once each frame
- Source