Skip to main content

Node

Description:

  Class used for building a hierarchical tree structure of game objects.

Class Object: Node Class.

Inherits from: Object.

order

Type: Field.

Description:

  The order of the node in the parent's children array.

Signature:

order: integer

angle

Type: Field.

Description:

  The rotation angle of the node in degrees.

Signature:

angle: number

angleX

Type: Field.

Description:

  The X-axis rotation angle of the node in degrees.

Signature:

angleX: number

angleY

Type: Field.

Description:

  The Y-axis rotation angle of the node in degrees.

Signature:

angleY: number

scaleX

Type: Field.

Description:

  The X-axis scale factor of the node.

Signature:

scaleX: number

scaleY

Type: Field.

Description:

  The Y-axis scale factor of the node.

Signature:

scaleY: number

x

Type: Field.

Description:

  The X-axis position of the node.

Signature:

x: number

y

Type: Field.

Description:

  The Y-axis position of the node.

Signature:

y: number

z

Type: Field.

Description:

  The Z-axis position of the node.

Signature:

z: number

position

Type: Field.

Description:

  The position of the node as a Vec2 object.

Signature:

position: Vec2

skewX

Type: Field.

Description:

  The X-axis skew angle of the node in degrees.

Signature:

skewX: number

skewY

Type: Field.

Description:

  The Y-axis skew angle of the node in degrees.

Signature:

skewY: number

visible

Type: Field.

Description:

  Whether the node is visible.

Signature:

visible: boolean

anchor

Type: Field.

Description:

  The anchor point of the node as a Vec2 object.

Signature:

anchor: Vec2

width

Type: Field.

Description:

  The width of the node.

Signature:

width: number

height

Type: Field.

Description:

  The height of the node.

Signature:

height: number

size

Type: Field.

Description:

  The size of the node as a Size object.

Signature:

size: Size

tag

Type: Field.

Description:

  The tag of the node as a string.

Signature:

tag: string

opacity

Type: Field.

Description:

  The opacity of the node, should be 0 to 1.0.

Signature:

opacity: number

color

Type: Field.

Description:

  The color of the node as a Color object.

Signature:

color: Color

color3

Type: Field.

Description:

  The color of the node as a Color3 object.

Signature:

color3: Color3

passOpacity

Type: Field.

Description:

  Whether to pass the opacity value to child nodes.

Signature:

passOpacity: boolean

passColor3

Type: Field.

Description:

  Whether to pass the color value to child nodes.

Signature:

passColor3: boolean

transformTarget

Type: Field.

Description:

  The target node acts as a parent node for transforming this node.

Signature:

transformTarget: Node

scheduler

Type: Field.

Description:

  The scheduler used for scheduling update and action callbacks.

Signature:

scheduler: Scheduler

hasChildren

Type: Readonly Field.

Description:

  Whether the node has children.

Signature:

const hasChildren: boolean

children

Type: Readonly Field.

Description:

  The children of the node as an Array object, could be nil.

Signature:

const children: Array

parent

Type: Readonly Field.

Description:

  The parent node of the node.

Signature:

const parent: Node

boundingBox

Type: Readonly Field.

Description:

  The bounding box of the node as a Rect object.

Signature:

const boundingBox: Rect

running

Type: Readonly Field.

Description:

  Whether the node is currently running in a scene tree.

Signature:

const running: boolean

scheduled

Type: Readonly Field.

Description:

  Whether the node is currently scheduling a function or a coroutine for updates.

Signature:

const scheduled: boolean

actionCount

Type: Readonly Field.

Description:

  The number of actions currently running on the node.

Signature:

const actionCount: integer

data

Type: Readonly Field.

Description:

  Additional data stored on the node as a Dictionary object.

Signature:

const data: Dictionary

touchEnabled

Type: Field.

Description:

  Whether touch events are enabled on the node.

Signature:

touchEnabled: boolean

swallowTouches

Type: Field.

Description:

  Whether the node should swallow touch events.

Signature:

swallowTouches: boolean

swallowMouseWheel

Type: Field.

Description:

  Whether the node should swallow mouse wheel events.

Signature:

swallowMouseWheel: boolean

keyboardEnabled

Type: Field.

Description:

  Whether keyboard events are enabled on the node.

Signature:

keyboardEnabled: boolean

controllerEnabled

Type: Field.

Description:

  Whether controller events are enabled on the node.

Signature:

controllerEnabled: boolean

renderGroup

Type: Field.

Description:

  Whether to group the node's rendering with all its recursive children.

Signature:

renderGroup: boolean

showDebug

Type: Field.

Description:

  Whether debug graphic should be displayed for the node.

Signature:

showDebug: boolean

renderOrder

Type: Field.

Description:

  The rendering order number for group rendering. Nodes with lower rendering orders are rendered earlier.

Signature:

renderOrder: integer

addChild

Type: Function.

Description:

  Adds a child node to the current node.

Signature:

addChild: function(
self: Node,
child: Node,
order?: integer --[[0]],
tag?: string --[[""]]
)

Parameters:

ParameterTypeDescription
childNodeThe child node to add.
orderinteger[optional] The drawing order of the child node. Default is 0.
tagstring[optional] The tag of the child node. Default is an empty string.

addTo

Type: Function.

Description:

  Adds the current node to a parent node.

Signature:

addTo: function(
self: Node,
parent: Node,
order?: integer --[[0]],
tag?: string --[[""]]
): Node

Parameters:

ParameterTypeDescription
parentNodeThe parent node to add the current node to.
orderinteger[optional] The drawing order of the current node. Default is 0.
tagstring[optional] The tag of the current node. Default is an empty string.

Returns:

Return TypeDescription
NodeThe current node.

removeChild

Type: Function.

Description:

  Removes a child node from the current node.

Signature:

removeChild: function(
self: Node,
child: Node,
cleanup?: boolean --[[true]]
)

Parameters:

ParameterTypeDescription
childNodeThe child node to remove.
cleanupboolean[optional] Whether to cleanup the child node. Default is true.

removeChildByTag

Type: Function.

Description:

  Removes a child node from the current node by tag.

Signature:

removeChildByTag: function(
self: Node,
tag: string,
cleanup?: boolean --[[true]]
)

Parameters:

ParameterTypeDescription
tagstringThe tag of the child node to remove.
cleanupboolean[optional] Whether to cleanup the child node. Default is true.

removeAllChildren

Type: Function.

Description:

  Removes all child nodes from the current node.

Signature:

removeAllChildren: function(
self: Node,
cleanup?: boolean --[[true]]
)

Parameters:

ParameterTypeDescription
cleanupboolean[optional] Whether to cleanup the child nodes. Default is true.

removeFromParent

Type: Function.

Description:

  Removes the current node from its parent node.

Signature:

removeFromParent: function(
self: Node,
cleanup?: boolean --[[true]]
)

Parameters:

ParameterTypeDescription
cleanupboolean[optional] Whether to cleanup the current node. Default is true.

moveToParent

Type: Function.

Description:

  Moves the current node to a new parent node without triggering node events.

Signature:

moveToParent: function(self: Node, parent: Node)

Parameters:

ParameterTypeDescription
parentNodeThe new parent node to move the current node to.

cleanup

Type: Function.

Description:

  Cleans up the current node.

Signature:

cleanup: function(self: Node)

getChildByTag

Type: Function.

Description:

  Gets a child node by tag.

Signature:

getChildByTag: function(self: Node, tag: string): Node

Parameters:

ParameterTypeDescription
tagstringThe tag of the child node to get.

Returns:

Return TypeDescription
NodeThe child node, or nil if not found.

schedule

Type: Function.

Description:

  Schedules a function to run every frame.

Signature:

schedule: function(self: Node, func: function(number): boolean)

Parameters:

ParameterTypeDescription
funcfunctionThe function to run, return true to stop.

schedule

Type: Function.

Description:

  Schedules a coroutine to run.

Signature:

schedule: function(self: Node, job: Routine.Job)

Parameters:

ParameterTypeDescription
jobRoutine.JobThe coroutine to run, return or yield true to stop.

unschedule

Type: Function.

Description:

  Unschedules the current node's scheduled function or coroutine.

Signature:

unschedule: function(self: Node)

convertToNodeSpace

Type: Function.

Description:

  Converts a point in world space to node space.

Signature:

convertToNodeSpace: function(self: Node, worldPoint: Vec2): Vec2

Parameters:

ParameterTypeDescription
worldPointVec2The point to convert.

Returns:

Return TypeDescription
Vec2The converted point.

convertToNodeSpace

Type: Function.

Description:

  Converts a point in world space to node space.

Signature:

convertToNodeSpace: function(self: Node, worldPoint: Vec2, z: number): Vec2, number

Parameters:

ParameterTypeDescription
worldPointVec2The point to convert.
znumberThe z-coordinate of the point.

Returns:

Return TypeDescription
Vec2The converted point.
numberThe converted z-coordinate.

convertToWorldSpace

Type: Function.

Description:

  Converts a point from node space to world space.

Signature:

convertToWorldSpace: function(self: Node, nodePoint: Vec2): Vec2

Parameters:

ParameterTypeDescription
nodePointVec2The point in node space.

Returns:

Return TypeDescription
Vec2The converted point in world space.

convertToWorldSpace

Type: Function.

Description:

  Converts a point from node space to world space.

Signature:

convertToWorldSpace: function(self: Node, nodePoint: Vec2, z: number): Vec2, number

Parameters:

ParameterTypeDescription
nodePointVec2The point in node space.
znumberThe z coordinate in node space.

Returns:

Return TypeDescription
Vec2The converted point in world space.
numberThe converted z coordinate in world space .

convertToWindowSpace

Type: Function.

Description:

  Converts a point from node space to window space.

Signature:

convertToWindowSpace: function(self: Node, nodePoint: Vec2, callback: function(Vec2))

Parameters:

ParameterTypeDescription
nodePointVec2The point in node space.
callbackfunctionThe callback function to receive the converted point in window space.

eachChild

Type: Function.

Description:

  Calls the given function for each child node of this node.

Signature:

eachChild: function(self: Node, func: function(Node): boolean): boolean

Parameters:

ParameterTypeDescription
funcfunctionThe function to call for each child node. The function should return a boolean value indicating whether to continue the iteration. Return true to stop iteration.

Returns:

Return TypeDescription
booleanFalse if all children have been visited, true if the iteration was interrupted by the function.

traverse

Type: Function.

Description:

  Traverses the node hierarchy starting from this node and calls the given function for each visited node. The nodes without TraverseEnabled flag are not visited.

Signature:

traverse: function(self: Node, func: function(Node): boolean): boolean

Parameters:

ParameterTypeDescription
funcfunctionThe function to call for each visited node. The function should return a boolean value indicating whether to continue the traversal. Return true to stop iteration.

Returns:

Return TypeDescription
booleanFalse if all nodes have been visited, true if the traversal was interrupted by the function.

traverseAll

Type: Function.

Description:

  Traverses the entire node hierarchy starting from this node and calls the given function for each visited node.

Signature:

traverseAll: function(self: Node, func: function(Node): boolean): boolean

Parameters:

ParameterTypeDescription
funcfunctionThe function to call for each visited node. The function should return a boolean value indicating whether to continue the traversal.

Returns:

Return TypeDescription
booleanTrue if all nodes have been visited, false if the traversal was interrupted by the function.

runAction

Type: Function.

Description:

  Runs the given action on this node.

Signature:

runAction: function(self: Node, action: Action, loop?: boolean): number

Parameters:

ParameterTypeDescription
actionActionThe action to run.
loopboolean[optional] Whether to loop the action. Default is false.

Returns:

Return TypeDescription
numberThe duration of the newly running action in seconds.

runAction

Type: Function.

Description:

  Runs an action defined by the given action definition on this node.

Signature:

runAction: function(self: Node, actionDef: ActionDef, loop?: boolean): number

Parameters:

ParameterTypeDescription
actionDefActionDefThe action definition to run.
loopboolean[optional] Whether to loop the action. Default is false.

Returns:

Return TypeDescription
numberThe duration of the newly running action in seconds.

stopAllActions

Type: Function.

Description:

  Stops all actions running on this node.

Signature:

stopAllActions: function(self: Node)

perform

Type: Function.

Description:

  Runs the given action immediately without adding it to the action queue.

Signature:

perform: function(self: Node, action: Action, loop?: boolean): number

Parameters:

ParameterTypeDescription
actionActionThe action to run.
loopboolean[optional] Whether to loop the action. Default is false.

Returns:

Return TypeDescription
numberThe duration of the newly running action.

perform

Type: Function.

Description:

  Runs an action defined by the given action definition right after clear all the previous running actions.

Signature:

perform: function(self: Node, actionDef: ActionDef, loop?: boolean): number

Parameters:

ParameterTypeDescription
actionDefActionDefThe action definition to run.
loopboolean[optional] Whether to loop the action. Default is false.

Returns:

Return TypeDescription
numberThe duration of the newly running action.

stopAction

Type: Function.

Description:

  Stops the given action running on this node.

Signature:

stopAction: function(self: Node, action: Action)

Parameters:

ParameterTypeDescription
actionActionThe action to stop.

alignItemsVertically

Type: Function.

Description:

  Vertically aligns all child nodes of this node.

Signature:

alignItemsVertically: function(
self: Node,
padding?: number --[[10]]
): Size

Parameters:

ParameterTypeDescription
paddingnumber[optional] The padding between child nodes. Defaults to 10.

Returns:

Return TypeDescription
SizeThe size of the aligned child nodes.

alignItemsVertically

Type: Function.

Description:

  Vertically aligns all child nodes within the node using the given size and padding.

Signature:

alignItemsVertically: function(
self: Node,
size: Size,
padding?: number --[[10]]
): Size

Parameters:

ParameterTypeDescription
sizeSizeThe size to use for alignment.
paddingnumber[optional] The amount of padding to use between each child node (default is 10).

Returns:

Return TypeDescription
SizeThe size of the node after alignment.

alignItemsHorizontally

Type: Function.

Description:

  Horizontally aligns all child nodes within the node using the given padding.

Signature:

alignItemsHorizontally: function(
self: Node,
padding?: number --[[10]]
): Size

Parameters:

ParameterTypeDescription
paddingnumber[optional] The amount of padding to use between each child node (default is 10).

Returns:

Return TypeDescription
SizeThe size of the node after alignment.

alignItemsHorizontally

Type: Function.

Description:

  Horizontally aligns all child nodes within the node using the given size and padding.

Signature:

alignItemsHorizontally: function(
self: Node,
size: Size,
padding?: number --[[10]]
): Size

Parameters:

ParameterTypeDescription
sizeSizeThe size to hint for alignment.
paddingnumber[optional] The amount of padding to use between each child node (default is 10).

Returns:

Return TypeDescription
SizeThe size of the node after alignment.

alignItems

Type: Function.

Description:

  Aligns all child nodes within the node using the given size and padding.

Signature:

alignItems: function(
self: Node,
padding?: number --[[10]]
): Size

Parameters:

ParameterTypeDescription
paddingnumber[optional] The amount of padding to use between each child node (default is 10).

Returns:

Return TypeDescription
SizeThe size of the node after alignment.

alignItems

Type: Function.

Description:

  Aligns all child nodes within the node using the given size and padding.

Signature:

alignItems: function(
self: Node,
size: Size,
padding?: number --[[10]]
): Size

Parameters:

ParameterTypeDescription
sizeSizeThe size to use for alignment.
paddingnumber[optional] The amount of padding to use between each child node (default is 10).

Returns:

Return TypeDescription
SizeThe size of the node after alignment.

moveAndCullItems

Type: Function.

Description:

  Moves and changes child nodes' visibility based on their position in parent's area.

Signature:

moveAndCullItems: function(self: Node, delta: Vec2)

Parameters:

ParameterTypeDescription
deltaVec2The distance to move its children.

attachIME

Type: Function.

Description:

  Attaches the input method editor (IME) to the node. Makes node recieving "AttachIME", "DetachIME", "TextInput", "TextEditing" events.

Signature:

attachIME: function(self: Node)

detachIME

Type: Function.

Description:

  Detaches the input method editor (IME) from the node.

Signature:

detachIME: function(self: Node)

gslot

Type: Function.

Description:

  Gets the global event listener associated with the given event name in this node.

Signature:

gslot: function(self: Node, eventName: string): {GSlot}

Parameters:

ParameterTypeDescription
eventNamestringThe name of the global event.

Returns:

Return TypeDescription
{GSlot}All the global event listeners associated with the event.

gslot

Type: Function.

Description:

  Associates the given event handler function with a global event.

Signature:

gslot: function(self: Node, eventName: string, handler: function()): GSlot

Parameters:

ParameterTypeDescription
eventNamestringThe name of the global event.
handlerfunctionThe handler function to associate with the event.

Returns:

Return TypeDescription
GSlotThe global event listener associated with the event in this node.

slot

Type: Function.

Description:

  Gets the node event listener associated with the given node event name.

Signature:

slot: function(self: Node, eventName: string): Slot

Parameters:

ParameterTypeDescription
eventNamestringThe name of the node event.

Returns:

Return TypeDescription
SlotThe node event listener associated with the node event.

slot

Type: Function.

Description:

  Associates the given handler function with the node event.

Signature:

slot: function(self: Node, eventName: string, handler: function())

Parameters:

ParameterTypeDescription
eventNamestringThe name of the node event.
handlerfunctionThe handler function to associate with the node event.

emit

Type: Function.

Description:

  Emits a node event with a given event name and arguments.

Signature:

emit: function(self: Node, eventName: string, ...: any)

Parameters:

ParameterTypeDescription
eventNamestringThe name of the node event.
......anyThe arguments to pass to the node event handler functions.

grab

Type: Function.

Description:

  Creates or removes a texture grabber for the specified node.

Signature:

grab: function(
self: Node,
enabled?: boolean --[[true]]
): Grabber

Parameters:

ParameterTypeDescription
enabledboolean[optional] Whether to enable or disable the grabber. Default is true.

Returns:

Return TypeDescription
GrabberA Grabber object when enabled.

grab

Type: Function.

Description:

  Creates a texture grabber for the specified node with a specified grid size.

Signature:

grab: function(self: Node, gridX: number, gridY: number): Grabber

Parameters:

ParameterTypeDescription
gridXnumberThe number of horizontal grid cells to divide the grabber into.
gridYnumberThe number of vertical grid cells to divide the grabber into.

Returns:

Return TypeDescription
GrabberA Grabber object.