Skip to content
reduz edited this page Feb 23, 2014 · 15 revisions

Node

####Inherits: Object ####Category: Core

Brief Description

Base class for all the "Scene" elements.

Member Functions

Signals

  • enter&#95scene ( )
  • renamed ( )
  • exit&#95scene ( )

Numeric Constants

  • NOTIFICATION_ENTER_SCENE = 10 - Notification received when the node enters the Scene Tree and gains access to the [RootNode]. Note that children nodes will not have received the notification at that time yet.
  • NOTIFICATION_EXIT_SCENE = 11 - Notification received when the node exits the Scene Tree and loses access to the [RootNode]. Note that parent nodes will not have received the notification at that time yet.
  • NOTIFICATION_MOVED_IN_PARENT = 12
  • NOTIFICATION_READY = 13
  • NOTIFICATION_FIXED_PROCESS = 16
  • NOTIFICATION_PROCESS = 17 - Notification received every frame when the process flag is set (see [method set_process]).
  • NOTIFICATION_PARENTED = 18 - Notification received when a node is set as a child of another node. Note that this doesn't mean that a node entered the Scene Tree.
  • NOTIFICATION_UNPARENTED = 19 - Notification received when a node is unparented (parent removed it from the list of children).
  • NOTIFICATION_PAUSED = 14
  • NOTIFICATION_UNPAUSED = 15
  • PAUSE_MODE_INHERIT = 0
  • PAUSE_MODE_STOP = 1
  • PAUSE_MODE_PROCESS = 2

Description

Nodes can be set as children of other nodes, resulting in a tree arrangement. Any tree of nodes is called a "Scene". Scenes can be saved to disk, and then instanced into other scenes. This allows for very high flexibility in the architecture and data model of the projects. SceneMainLoop contains the "active" tree of nodes, and a node becomes active (receinving NOTIFICATION_ENTER_SCENE) when added to that tree. A node can contain any number of nodes as a children (but there is only one tree root) with the requirement that no two childrens with the same name can exist. Nodes can, optionally, be added to groups. This makes it easy to reach a number of nodes from the code (for example an "enemies" group). Nodes can be set to "process" state, so they constantly receive a callback requesting them to process (do anything). Normal processing (&#95process) happens as fast as possible and is dependent on the frame rate, so the processing time delta is variable. Fixed processing (&#95fixed&#95process) happens a fixed amount of times per second (by default 60) and is useful to link itself to the physics. Nodes can also process input events. When set, the &#95input function will be called with every input that the program receives. Since this is usually too overkill (unless used for simple projects), an &#95unhandled&#95input function is called when the input was not handled by anyone else (usually, GUI Control nodes). To keep track of the scene hieararchy (specially when instancing scenes into scenes) an "owner" can be set to a node. This keeps track of who instanced what. This is mostly useful when writing editors and tools, though. Finally, when a node is freed, it will free all its children nodes too.

Member Function Description

  • void &#95enter&#95scene ( ) virtual

Called when entered the scene.

  • void &#95exit&#95scene ( ) virtual

Called when being removed from the scene.

  • void &#95fixed&#95process ( real delta ) virtual

Called for fixed processing (synced to the physics).

Called when any input happens (also must enable with set&#95process&#95input or the property).

  • void &#95process ( real delta ) virtual

Called for processing. This is called every frame, with the delta time from the previous frame.

  • void &#95ready ( ) virtual

Called when ready (entered scene and children entered too).

  • void &#95unhandled&#95input ( InputEvent event ) virtual

Called when any input happens that was not handled by something else (also must enable with set&#95process&#95unhandled&#95input or the property).

  • void &#95unhandled&#95key&#95input ( InputEvent key_event ) virtual

Called when any key input happens that was not handled by something else.

  • void set&#95name ( String name )

Set the name of the Node. Name must be unique within parent, and setting an already existing name will cause for the node to be automatically renamed.

  • String get&#95name ( ) const

Return the name of the Node. Name is be unique within parent.

  • void add&#95child ( Node node )

Add a child Node. Nodes can have as many children as they want, but every child must have a unique name. Children nodes are automatically deleted when the parent node is deleted, so deleting a whole scene is performed by deleting its topmost node.

  • void remove&#95child ( Node node )

Remove a child Node. Node is NOT deleted and will have to be deleted manually.

  • int get&#95child&#95count ( ) const

Return the amount of children nodes.

  • Node get&#95child ( int idx ) const

Return a children node by it"apos;s index (see get&#95child&#95count). This method is often used for iterating all children of a node.

Fetch a node. "path" must be valid (or else error will occur) and can be either the name of a child node, a relative path (from the current node to another node), or an absolute path to a node. Examples ofa paths are: get_node("Sword") , get_node("../Swamp/Alligator") , get_node("/MyGame"). Note: fetching absolute paths only works when the node is inside the scene tree (see is&#95inside&#95scene).

  • Parent get&#95parent ( ) const

Return the parent Node of the current Node, or an empty Object if the node lacks a parent.

  • bool is&#95inside&#95scene ( ) const

Return wether the node is inside a scene tree (a tree where the topmost node is a [RootNode])

  • bool is&#95a&#95parent&#95of ( Node node ) const

Return true if the "node" argument is a direct or indirect child of the current node, otherwise return false.

  • bool is&#95greater&#95than ( Node node ) const

Return true if "node" occurs later in the scene hierarchy than the current node, otherwise return false.

Return the absolute path of the current node. This only works if the curent node is inside the scene tree (see is&#95inside&#95scene).

Return the relative path from the current node to the specified node in "node" argument. Both nodes must be in the same scene, or else the function will fail.

  • void add&#95to&#95group ( String group, bool arg1=false )

Add a node to a group. Groups are helpers to name and organize group of nodes, like for example: "Enemies" "Collectables", etc. A Node can be in any number of groups. Nodes can be assigned a group at any time, but will not be added to it until they are inside the scene tree (see is&#95inside&#95scene).

  • void remove&#95from&#95group ( String group )

Remove a node from a group.

  • void move&#95child ( Node child_node, int to_pos )

Move a child node to a different position (order) amongst the other children. Since calls, signals, etc are performed by tree order, changing the order of chilren nodes may be useful.

  • void raise ( )

Move this node to the top of the array of nodes of the parent node. This is often useful on GUIs (Control), because their order of drawing fully depends on their order in the tree.

  • void set&#95owner ( Node owner )

Set the node owner. A node can have any other node as owner (as long as a valid parent, grandparent, etc ascending in the tree). When saving a node (using SceneSaver) all the nodes it owns will be saved with it. This allows to create complex SceneTrees, with instancing and subinstancing.

  • Node get&#95owner ( ) const

Get the node owner (see set&#95node&#95owner).

  • void remove&#95and&#95skip ( )

Remove a node and set all its children as childrens of the parent node (if exists). All even subscriptions that pass by the removed node will be unsubscribed.

  • int get&#95index ( ) const

Get the node index in the parent (assuming it has a parent).

  • void print&#95tree ( )

Print the screne to stdout. Used mainly for debugging purposes.

  • void set&#95filename ( String filename )

A node can contain a filename. This filename should not be changed by the user, unless writing editors and tools. When a scene is instanced from a file, it topmost node contains the filename from where it was loaded.

  • String get&#95filename ( ) const

Return a filename that may be containedA node can contained by the node. When a scene is instanced from a file, it topmost node contains the filename from where it was loaded (see set&#95filename).

  • void propagate&#95notification ( int what )

Notify the current node and all its chldren recursively by calling notification() in all of them.

  • void set&#95fixed&#95process ( bool enable )

Enables or disables node fixed framerate processing. When a node is being processed, it will receive a NOTIFICATION_PROCESS at a fixed (usually 60fps, check OS to change that) interval (and the &#95fixed&#95process callback will be called if exists). It is common to check how much time was elapsed since the previous frame by calling get&#95fixed&#95process&#95time.

  • real get&#95fixed&#95process&#95delta&#95time ( ) const

Return the time elapsed since the last fixed frame. This is always the same in fixed proecssing unless the frames per second is changed in OS.

  • bool is&#95fixed&#95processing ( ) const

Return true if fixed processing is enabled (see set&#95fixed&#95process).

  • void set&#95process ( bool enable )

Enables or disables node processing. When a node is being processed, it will receive a NOTIFICATION_PROCESS on every drawn frame (and the &#95process callback will be called if exists). It is common to check how much time was elapsed since the previous frame by calling get&#95process&#95time.

  • real get&#95process&#95delta&#95time ( ) const

Return the time elapsed (in seconds) since the last process callback. This is almost always different each time.

  • bool is&#95processing ( ) const

Return wether processing is enabled in the current node (see set&#95process).

  • void set&#95process&#95input ( bool enable )

Enable input processing for node. This is not requiered for GUI controls! It hooks up the node to receive all input (see &#95input).

  • bool is&#95processing&#95input ( ) const

Return true if the node is processing input (see set&#95process&#95input).

  • void set&#95process&#95unhandled&#95input ( bool enable )

Enable unhandled input processing for node. This is not requiered for GUI controls! It hooks up the node to receive all input that was not previously handled before (usually by a Control). (see &#95unhandled&#95input).

  • bool is&#95processing&#95unhandled&#95input ( ) const

Return true if the node is processing unhandled input (see set&#95process&#95unhandled&#95input).

  • bool can&#95process ( ) const

Return true if the node can process.

Get the current SceneMainLoop. Only returned if the node is inside the scene, else returns null.

  • Node duplicate ( ) const

Return a duplicate of the scene, with all nodes and parameters copied. Subscriptions will not be duplicated.

  • void replace&#95by ( Node node, bool keep_data=false )

Replace a node in a scene by a given one. Subscriptions that pass through this node will be lost.

Clone this wiki locally