Node [constructor]
Nodes define hierarchy and geometrical transformations. They can be moved (translated), scaled and rotated.
A Node is either mounted or unmounted. Unmounted nodes are detached from the scene graph. Unmounted nodes have no parent node, while each mounted node has exactly one parent. Nodes have an arbitrary number of children, which can be dynamically added using {@link Node#addChild}.
Each Node has an arbitrary number of components
. Those components can
send draw
commands to the renderer or mutate the node itself, in which case
they define behavior in the most explicit way. Components that send draw
commands are considered renderables
. From the node's perspective, there is
no distinction between nodes that send draw commands and nodes that define
behavior.
Because of the fact that Nodes themself are very unopinioted (they don't
"render" to anything), they are often being subclassed in order to add e.g.
components at initialization to them. Because of this flexibility, they might
as well have been called Entities
.
new Node()
Instance methods
._init()
Protected method. Initializes a node with a default Transform and Size component
._setParent(parent)
Protected method. Sets the parent of this node such that it can be looked up.
Parameters:
Name | Type | Description |
---|---|---|
parent | Node | The node to set as the parent of this |
._setMounted(mounted, path)
Protected method. Sets the mount state of the node. Should only be called by the dispatch
Parameters:
Name | Type | Description |
---|---|---|
mounted | Boolean | whether or not the Node is mounted. |
path | String | The path that the node will be mounted to |
._setShown(shown)
Protected method, sets whether or not the Node is shown. Should only be called by the dispatch
Parameters:
Name | Type | Description |
---|---|---|
shown | Boolean | whether or not the node is shown |
._setUpdater(updater)
Protected method. Sets the updater of the node.
Parameters:
Name | Type | Description |
---|---|---|
updater | FamousEngine | the Updater of the node. |
.getLocation()
Determine the node's location in the scene graph hierarchy.
A location of body/0/1
can be interpreted as the following scene graph
hierarchy (ignoring siblings of ancestors and additional child nodes):
Context:body
-> Node:0
-> Node:1
, where Node:1
is the node the
getLocation
method has been invoked on.
.emit(event, payload)
Dispatches the event using the Dispatch. All descendent nodes will receive the dispatched event.
Parameters:
Name | Type | Description |
---|---|---|
event | String | Event type. |
payload | Object | Event object to be dispatched. |
.sendDrawCommand()
.getValue()
Recursively serializes the Node, including all previously added components.
.getComputedValue()
Similar to {@link Node#getValue}, but returns the actual "computed" value. E.g. a proportional size of 0.5 might resolve into a "computed" size of 200px (assuming the parent has a width of 400px).
.getChildren()
Retrieves all children of the current node.
.getRawChildren()
Method used internally to retrieve the children of a node. Each index in the returned array represents a path fragment.
.getParent()
Retrieves the parent of the current node. Unmounted nodes do not have a parent node.
.requestUpdate(requester)
Schedules the {@link Node#update} function of the node to be invoked on the next frame (if no update during this frame has been scheduled already). If the node is currently being updated (which means one of the requesters invoked requestsUpdate while being updated itself), an update will be scheduled on the next frame.
Parameters:
Name | Type | Description |
---|---|---|
requester | Object | If the requester has an |
.requestUpdateOnNextTick(requester)
Schedules an update on the next tick. Similarily to
{@link Node#requestUpdate}, requestUpdateOnNextTick
schedules the node's
onUpdate
function to be invoked on the frame after the next invocation on
the node's onUpdate function.
Parameters:
Name | Type | Description |
---|---|---|
requester | Object | If the requester has an |
.isMounted()
Checks if the node is mounted. Unmounted nodes are detached from the scene graph.
.isRendered()
Checks if the node is being rendered. A node is being rendererd when it is mounted to a parent node and shown.
.isShown()
Checks if the node is visible ("shown").
.getOpacity()
Determines the node's relative opacity. The opacity needs to be within [0, 1], where 0 indicates a completely transparent, therefore invisible node, whereas an opacity of 1 means the node is completely solid.
.getMountPoint()
Determines the node's previously set mount point.
.getAlign()
Determines the node's previously set align.
.getOrigin()
Determines the node's previously set origin.
.getPosition()
Determines the node's previously set position.
.getRotation()
Returns the node's current rotation
.getScale()
Returns the scale of the node
.getSizeMode()
Returns the current size mode of the node
.getProportionalSize()
Returns the current proportional size
.getDifferentialSize()
Returns the differential size of the node
.getAbsoluteSize()
Returns the absolute size of the node
.getRenderSize()
Returns the current Render Size of the node. Note that the render size is asynchronous (will always be one frame behind) and needs to be explicitely calculated by setting the proper size mode.
.getSize()
Returns the external size of the node
.getTransform()
Returns the current world transform of the node
.getUIEvents()
Get the list of the UI Events that are currently associated with this node
.addChild(child)
Adds a new child to this node. If this method is called with no argument it will create a new node, however it can also be called with an existing node which it will append to the node that this method is being called on. Returns the new or passed in node.
Parameters:
Name | Type | Description |
---|---|---|
child | Node | the node to appended or no node to create a new node. |
.removeChild(child)
Removes a child node from another node. The passed in node must be a child of the node that this method is called upon.
Parameters:
Name | Type | Description |
---|---|---|
child | Node | node to be removed |
.addComponent(component)
Each component can only be added once per node.
Parameters:
Name | Type | Description |
---|---|---|
component | Object | A component to be added. |
.getComponent(index)
Parameters:
Name | Type | Description |
---|---|---|
index | Number | Index at which the component has been registered
(using |
.removeComponent(component)
Removes a previously via {@link Node#addComponent} added component.
Parameters:
Name | Type | Description |
---|---|---|
component | Object | An component that has previously been added using {@link Node#addComponent}. |
.removeUIEvent(eventName)
Removes a node's subscription to a particular UIEvent. All components on the node will have the opportunity to remove all listeners depending on this event.
Parameters:
Name | Type | Description |
---|---|---|
eventName | String | the name of the event |
.addUIEvent(eventName)
Subscribes a node to a UI Event. All components on the node will have the opportunity to begin listening to that event and alerting the scene graph.
Parameters:
Name | Type | Description |
---|---|---|
eventName | String | the name of the event |
._requestUpdate(force)
Private method for the Node to request an update for itself.
Parameters:
Name | Type | Description |
---|---|---|
force | Boolean | whether or not to force the update |
._vecOptionalSet(vec, index, val)
Private method to set an optional value in an array, and request an update if this changes the value of the array.
Parameters:
Name | Type | Description |
---|---|---|
vec | Array | the array to insert the value into |
index | Number | the index at which to insert the value |
val | Any | the value to potentially insert (if not null or undefined) |
.show()
Shows the node, which is to say, calls onShow on all of the node's components. Renderable components can then issue the draw commands necessary to be shown.
.hide()
Hides the node, which is to say, calls onHide on all of the node's components. Renderable components can then issue the draw commands necessary to be hidden
.setAlign(x, y, z)
Sets the align value of the node. Will call onAlignChange on all of the Node's components.
Parameters:
Name | Type | Description |
---|---|---|
x | Number | Align value in the x dimension. |
y | Number | Align value in the y dimension. |
z | Number | Align value in the z dimension. |
.setMountPoint(x, y, z)
Sets the mount point value of the node. Will call onMountPointChange on all of the node's components.
Parameters:
Name | Type | Description |
---|---|---|
x | Number | MountPoint value in x dimension |
y | Number | MountPoint value in y dimension |
z | Number | MountPoint value in z dimension |
.setOrigin(x, y, z)
Sets the origin value of the node. Will call onOriginChange on all of the node's components.
Parameters:
Name | Type | Description |
---|---|---|
x | Number | Origin value in x dimension |
y | Number | Origin value in y dimension |
z | Number | Origin value in z dimension |
.setPosition(x, y, z)
Sets the position of the node. Will call onPositionChange on all of the node's components.
Parameters:
Name | Type | Description |
---|---|---|
x | Number | Position in x |
y | Number | Position in y |
z | Number | Position in z |
.setRotation(x, y, z, w)
Sets the rotation of the node. Will call onRotationChange on all of the node's components. This method takes either Euler angles or a quaternion. If the fourth argument is undefined Euler angles are assumed.
Parameters:
Name | Type | Description |
---|---|---|
x | Number | Either the rotation around the x axis or the magnitude in x of the axis of rotation. |
y | Number | Either the rotation around the y axis or the magnitude in y of the axis of rotation. |
z | Number | Either the rotation around the z axis or the magnitude in z of the axis of rotation. |
w | Number | the amount of rotation around the axis of rotation, if a quaternion is specified. |
.setScale(x, y, z)
Sets the scale of the node. The default value is 1 in all dimensions. The node's components will have onScaleChanged called on them.
Parameters:
Name | Type | Description |
---|---|---|
x | Number | Scale value in x |
y | Number | Scale value in y |
z | Number | Scale value in z |
.setOpacity(val)
Sets the value of the opacity of this node. All of the node's components will have onOpacityChange called on them/
Parameters:
Name | Type | Description |
---|---|---|
val | Number | Value of the opacity. 1 is the default. |
.setSizeMode(x, y, z)
Sets the size mode being used for determining the node's final width, height and depth. Size modes are a way to define the way the node's size is being calculated. Size modes are enums set on the {@link Size} constructor (and aliased on the Node).
Parameters:
Name | Type | Description |
---|---|---|
x | SizeMode | The size mode being used for determining the size in x direction ("width"). |
y | SizeMode | The size mode being used for determining the size in y direction ("height"). |
z | SizeMode | The size mode being used for determining the size in z direction ("depth"). |
.setProportionalSize(x, y, z)
A proportional size defines the node's dimensions relative to its parents final size. Proportional sizes need to be within the range of [0, 1].
Parameters:
Name | Type | Description |
---|---|---|
x | Number | x-Size in pixels ("width"). |
y | Number | y-Size in pixels ("height"). |
z | Number | z-Size in pixels ("depth"). |
.setDifferentialSize(x, y, z)
Differential sizing can be used to add or subtract an absolute size from an
otherwise proportionally sized node.
E.g. a differential width of -10
and a proportional width of 0.5
is
being interpreted as setting the node's size to 50% of its parent's width
minus 10 pixels.
Parameters:
Name | Type | Description |
---|---|---|
x | Number | x-Size to be added to the relatively sized node in pixels ("width"). |
y | Number | y-Size to be added to the relatively sized node in pixels ("height"). |
z | Number | z-Size to be added to the relatively sized node in pixels ("depth"). |
.setAbsoluteSize(x, y, z)
Sets the node's size in pixels, independent of its parent.
Parameters:
Name | Type | Description |
---|---|---|
x | Number | x-Size in pixels ("width"). |
y | Number | y-Size in pixels ("height"). |
z | Number | z-Size in pixels ("depth"). |
.getFrame()
Method for getting the current frame. Will be deprecated.
.getComponents()
returns an array of the components currently attached to this node.
.update(time)
Enters the node's update phase while updating its own spec and updating its components.
Parameters:
Name | Type | Description |
---|---|---|
time | Number | high-resolution timestamp, usually retrieved using requestAnimationFrame |
.mount(path)
Mounts the node and therefore its subtree by setting it as a child of the passed in parent.
Parameters:
Name | Type | Description |
---|---|---|
path | String | unique path of node (e.g. |
.dismount()
Dismounts (detaches) the node from the scene graph by removing it as a child of its parent.
Members
._requestingUpdate
No description provided.
._inUpdate
No description provided.
._mounted
No description provided.
._shown
No description provided.
._updater
No description provided.
._opacity
No description provided.
._UIEvents
No description provided.
._updateQueue
No description provided.
._nextUpdateQueue
No description provided.
._freedComponentIndicies
No description provided.
._components
No description provided.
._freedChildIndicies
No description provided.
._children
No description provided.
._fullChildren
No description provided.
._parent
No description provided.
._id
No description provided.
._transformID
No description provided.
._sizeID
No description provided.