Node

A generic node object

Events

NameDescriptionArguments
addNode is added to the worldNone
deleteNode is removed from the worldNone

Constructor

new Node()

Creates a Node with the given position

Members

(readonly) nodeType

Type of node, ie Node or RigidBody

(readonly) position :vec

Position of the node

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

(readonly) angle :number

Angle, in radians

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

(readonly) children :Set

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

Type:
  • Set

Methods

(static) getUniqueId() → {number}

Generates a unique id for nodes

Returns:

A unique integer id

Type: 
number

add() → {Node}

Adds this node and its children, triggering the add event

Returns:

this

Type: 
Node

delete() → {Node}

Removes this node and its children, triggering the delete event

Returns:

this

Type: 
Node

isAdded() → {Boolean}

Gets if the node is added

Returns:

if the node is added

Type: 
Boolean

addChild(…children)

Adds all children to this node's children

Parameters:
NameTypeAttributesDescription
childrenNode<repeatable>

Children added

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

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

off(event, callback)

Unbinds a callback from an event

Parameters:
NameTypeDescription
eventstring

Name of the event

callbackfunction

Function to unbind

trigger(event, …args)

Triggers an event, firing all bound callbacks

Parameters:
NameTypeAttributesDescription
eventstring

Name of the event

args*<repeatable>

Arguments passed to callbacks