World

The game world

Constructor

new World(options)

Parameters:
NameTypeDescription
optionsobject

World options

Properties
NameTypeAttributesDefaultDescription
gravityvec<optional>
vec(0, 500)

Gravity in pixels / second

gridSizenumber<optional>
500

Size of broadphase grid in pixels

Extends

Members

(readonly) nodeType

Type of node, ie Node or RigidBody

Overrides

(readonly) position :vec

Position of the node

Type:
Overrides
To Do
  • Implement getPosition method and make this private

(readonly) angle :number

Angle, in radians

Type:
  • number
Overrides
To Do
  • Implement getAngle method and make this private

(readonly) children :Set

Children of the node To modify, use addChild or removeChild.

Type:
  • Set
Overrides

Methods

add() → {Node}

Adds this node and its children, triggering the add event

Overrides
Returns:

this

Type: 
Node

delete() → {Node}

Removes this node and its children, triggering the delete event

Overrides
Returns:

this

Type: 
Node

isAdded() → {Boolean}

Gets if the node is added

Overrides
Returns:

if the node is added

Type: 
Boolean

addChild(…children)

Adds all children to this node's children

Parameters:
NameTypeAttributesDescription
childrenNode<repeatable>

Children added

Overrides
Example
let parentNode = new Node();
let childNode = new Node();
node.addChild(childNode);

removeChild(…children)

Removes all children from this node's children

Parameters:
NameTypeAttributesDescription
childrenNode<repeatable>

Children removed

Example
let parentNode = new Node();
let childNode = new Node();
node.addChild(childNode); // node.children: Set {childNode}
node.removeChild(childNode); // node.children: Set {}

setPosition(position)

Sets this node's position to position

Parameters:
NameTypeDescription
positionvec

Position the node should be set to

Example
node.setPosition(new vec(100, 100)); // Sets node's position to (100, 100) 

translate(positionDelta)

Shifts this node's position by positionDelta

Parameters:
NameTypeDescription
positionDeltavec

Amount to shift the position

setAngle(angle)

Sets the node's angle to angle

Parameters:
NameTypeDescription
anglenumber

Angle body should be in radians

Overrides
Example
node.setAngle(Math.PI); // Sets node's angle to Pi radians, or 180 degrees

translateAngle(angle)

Rotates the body by angle- Relative

Parameters:
NameTypeDescription
anglenumber

Amount the body should be rotated, in radians

on(event, callback)

Bind a callback to an event

Parameters:
NameTypeDescription
eventstring

Name of the event

callbackfunction

Callback run when event is fired

Overrides

off(event, callback)

Unbinds a callback from an event

Parameters:
NameTypeDescription
eventstring

Name of the event

callbackfunction

Function to unbind

Overrides

trigger(event, …args)

Triggers an event, firing all bound callbacks

Parameters:
NameTypeAttributesDescription
eventstring

Name of the event

args*<repeatable>

Arguments passed to callbacks

Overrides