Constructor
new EngineObject(posopt, sizeopt, tileInfoopt, angleopt, coloropt, renderOrderopt)
Create an engine object and adds it to the list of objects
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | <optional> | vec2() | World space position of the object |
size | Vector2 | <optional> | vec2(1) | World space size of the object |
tileInfo | TileInfo | <optional> | Tile info to render object (undefined is untextured) | |
angle | number | <optional> | 0 | Angle the object is rotated by |
color | Color | <optional> | WHITE | 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
Properties| Type | Description |
|---|---|
| Color | Additive color to apply when rendered |
- Source
angle
Properties| Type | Description |
|---|---|
| number | Angle to rotate the object |
- Source
angleDamping
Properties| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
angleDamping | number | <optional> | objectDefaultAngleDamping | How much to slow down rotation each frame (0-1) |
- Source
angleVelocity
Properties| Type | Description |
|---|---|
| number | Angular velocity of the object |
- Source
children
Properties| Type | Description |
|---|---|
| Array.<EngineObject> | List of children of this object |
- Source
clampSpeed
Properties| Type | Description |
|---|---|
| boolean | Limit object speed along x and y axis |
- Source
collideRaycast
Properties| Type | Description |
|---|---|
| boolean | Object collides with raycasts |
- Source
collideSolidObjects
Properties| Type | Description |
|---|---|
| boolean | Object collides with solid objects |
- Source
collideTiles
Properties| Type | Description |
|---|---|
| boolean | Object collides with the tile collision |
- Source
color
Properties| Type | Description |
|---|---|
| Color | Color to apply when rendered |
- Source
damping
Properties| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
damping | number | <optional> | objectDefaultDamping | How much to slow down velocity each frame (0-1) |
- Source
drawSize
Properties| Type | Description |
|---|---|
| Vector2 | Size of object used for drawing, uses size if not set |
- Source
friction
Properties| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
friction | number | <optional> | objectDefaultFriction | How much friction to apply when sliding (0-1) |
- Source
gravityScale
Properties| Type | Description |
|---|---|
| number | How much to scale gravity by for this object |
- Source
groundObject
Properties| Type | Description |
|---|---|
| EngineObject | Object we are standing on, if any |
- Source
isSolid
Properties| Type | Description |
|---|---|
| boolean | Object collides with and blocks other objects |
- Source
localAngle
Properties| Type | Description |
|---|---|
| number | Local angle if child |
- Source
localPos
Properties| Type | Description |
|---|---|
| Vector2 | Local position if child |
- Source
mass
Properties| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
mass | number | <optional> | objectDefaultMass | How heavy the object is, static if 0 |
- Source
mirror
Properties| Type | Description |
|---|---|
| boolean | Should it flip along y axis when rendered |
- Source
parent
Properties| Type | Description |
|---|---|
| EngineObject | Parent of object if in local space |
- Source
pos
Properties| Type | Description |
|---|---|
| Vector2 | World space position of the object |
- Source
renderOrder
Properties| Type | Description |
|---|---|
| number | Objects are sorted by render order |
- Source
restitution
Properties| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
restitution | number | <optional> | objectDefaultRestitution | How bouncy the object is when colliding (0-1) |
- Source
size
Properties| Type | Description |
|---|---|
| Vector2 | World space width and height of the object |
- Source
spawnTime
Properties| Type | Description |
|---|---|
| number | Track when object was created |
- Source
tileInfo
Properties| Type | Description |
|---|---|
| TileInfo | Tile info to render object (undefined is untextured) |
- Source
velocity
Properties| Type | Description |
|---|---|
| Vector2 | Velocity of the object |
- Source
Methods
addChild(child, localPosopt, localAngleopt) → {EngineObject}
Attaches a child to this with a local transform, returns child for chaining
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
child | EngineObject | |||
localPos | Vector2 | <optional> | vec2() | |
localAngle | number | <optional> | 0 |
- Source
The child object added
- Type:
- EngineObject
applyAcceleration(acceleration)
Apply acceleration to this object (adjust velocity, not affected by mass)
| Name | Type | Description |
|---|---|---|
acceleration | Vector2 |
- Source
applyAngularAcceleration(acceleration)
Apply angular acceleration to this object
| Name | Type | Description |
|---|---|---|
acceleration | number |
- Source
applyForce(force)
Apply force to this object (adjust velocity, affected by mass)
| Name | Type | Description |
|---|---|---|
force | Vector2 |
- Source
collideWithObject(object) → {boolean}
Called by the engine to check if an object collision should be resolved. Return true for physics to resolve the collision or false to ignore and resolve it manually.
| Name | Type | Description |
|---|---|---|
object | EngineObject | the object to test against |
- Source
- true if the collision should be resolved by modifying it's position and velocity
- Type:
- boolean
collideWithTile(tileData, pos) → {boolean}
Called to check if a tile collision should be resolved. Return true for physics to resolve the collision or false to ignore and resolve it manually.
| Name | Type | Description |
|---|---|---|
tileData | number | the value of the tile at the position |
pos | Vector2 | tile where the collision occurred |
- Source
- true if the collision should be resolved by modifying it's position and velocity
- Type:
- boolean
destroy()
Destroy this object, destroy its children, detach its 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
getRight(scaleopt) → {Vector2}
Get this object's right vector
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
scale | number | <optional> | 1 | length of the vector |
- Source
- Type:
- Vector2
getSpeed() → {number}
Get the speed of this object
- Source
- Type:
- number
getUp(scaleopt) → {Vector2}
Get this object's up vector
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
scale | number | <optional> | 1 | length of the vector |
- Source
- Type:
- Vector2
isOverlapping(pos, sizeopt) → {boolean}
Check if overlapping a point or aligned bounding box
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | Center of box | ||
size | Vector2 | <optional> | vec2() | Size of box, uses a point if undefined |
- Source
- Type:
- boolean
isOverlappingObject(object) → {boolean}
Check if overlapping another engine object Collisions are resoloved to prevent overlaps
| Name | Type | Description |
|---|---|---|
object | EngineObject |
- Source
- Type:
- boolean
localToWorld(pos)
Convert from local space to world space
| Name | Type | Description |
|---|---|---|
pos | Vector2 | local space point |
- Source
localToWorldVector(vec)
Convert from local space to world space for a vector (rotation only)
| Name | Type | Description |
|---|---|---|
vec | Vector2 | local space vector |
- Source
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
renderDebugInfo()
Render debug info for this object
- 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? |
- Source
toString() → {string}
Returns string containing info about this object for debugging
- Source
- Type:
- string
update()
Update the object, called automatically by engine once each frame. Does nothing by default.
- Source
updatePhysics()
Update the object physics, called automatically by engine once each frame. Can be overridden to stop or change how physics works for an object.
- Source
updateTransforms()
Update the object transform, called automatically by engine even when paused
- Source
worldToLocal(pos)
Convert from world space to local space
| Name | Type | Description |
|---|---|---|
pos | Vector2 | world space point |
- Source
worldToLocalVector(vec)
Convert from world space to local space for a vector (rotation only)
| Name | Type | Description |
|---|---|---|
vec | Vector2 | world space vector |
- Source