Empty Node
Basic 2D transform node with position, rotation, scale, and hierarchy grouping.
Type: Node · Category: Core & 2D · Also found as: node, empty
A plain node: a transform (position, rotation, scale) and children. Use it to group nodes - move the group and everything under it moves - or as the root of a scene or a component, or to hold a script that has nothing to draw.
-- A spinning group: everything under this node turns with it.local Spinner = {}Spinner.properties = { speed = { type = "float", default = 90 } } -- degrees per second
function Spinner:update(dt) self.node.rotation = self.node.rotation + self.speed * dtend
return SpinnerProperties
Section titled “Properties”No reflected properties of its own: its settings are described above.
Plus the common properties every node has.
Lua methods
Section titled “Lua methods”Call them on the node (self.node in its script, or self.node:get_node("path")). Every node also has the Node methods.
Node:get_type()
Section titled “Node:get_type()”Gets the concrete runtime type of the node (e.g. “Node”, “TextureNode”, “DynamicBodyNode”, “CameraNode”).
if self.node:get_type() == "DynamicBodyNode" then Log.info("physics body") endReturns string
Node:get_name()
Section titled “Node:get_name()”Gets the display/debug name of the node.
Log.info("Spawned " .. self.node:get_name())Returns string
Node:set_name(name)
Section titled “Node:set_name(name)”Sets the display/debug name of the node.
self.node:set_name("Enemy_" .. tostring(index))namestring
Node:get_position()
Section titled “Node:get_position()”Gets the local position of the node.
local x, y = self.node:get_position()Returns number x Local X position, number y Local Y position
Node:set_position(x, y)
Section titled “Node:set_position(x, y)”Sets the local position of the node.
self.node:set_position(320, 180)xnumberLocal X positionynumberLocal Y position
Node:translate(dx, dy)
Section titled “Node:translate(dx, dy)”Translates the node position by the given delta offset.
self.node:translate(self.speed * dt, 0)dxnumberDelta XdynumberDelta Y
Node:get_rotation()
Section titled “Node:get_rotation()”Gets the local rotation of the node in degrees.
local angle = self.node:get_rotation()Returns number rotation Rotation in degrees
Node:set_rotation(degrees)
Section titled “Node:set_rotation(degrees)”Sets the local rotation of the node in degrees.
self.node:set_rotation(90)degreesnumberRotation in degrees
Node:rotate(degrees)
Section titled “Node:rotate(degrees)”Rotates the node by delta degrees.
self.node:rotate(180 * dt)degreesnumberDelta degrees
Node:get_scale()
Section titled “Node:get_scale()”Gets the local scale factor of the node.
local sx, sy = self.node:get_scale()Returns number sx Scale X, number sy Scale Y
Node:set_scale(sx, sy)
Section titled “Node:set_scale(sx, sy)”Sets the local scale factor of the node.
self.node:set_scale(-1, 1)sxnumberScale Xsy?numberScale Y (defaults to sx if omitted)
Node:get_global_position()
Section titled “Node:get_global_position()”Gets the world-space global position of the node calculated from parent transforms.
local gx, gy = self.node:get_global_position()Returns number x Global world X position, number y Global world Y position
Node:get_global_rotation()
Section titled “Node:get_global_rotation()”Gets the world-space global rotation of the node in degrees.
local world_angle = self.node:get_global_rotation()Returns number rotation Global world rotation in degrees
Node:is_enabled()
Section titled “Node:is_enabled()”Checks if the node is actively updated in the scene loop.
if not self.node:is_enabled() then return endReturns boolean
Node:set_enabled(enabled)
Section titled “Node:set_enabled(enabled)”Enables or disables updates for the node and its children.
Scene.find_node("Enemy"):set_enabled(false)enabledboolean
Node:is_visible()
Section titled “Node:is_visible()”Checks if the node is rendered in the scene draw loop.
local shown = self.node:is_visible()Returns boolean
Node:set_visible(visible)
Section titled “Node:set_visible(visible)”Sets whether the node is rendered.
self.node:get_node("Shield"):set_visible(true)visibleboolean
Node:get_parent()
Section titled “Node:get_parent()”Gets the parent node, or nil if this is a root node.
local parent = self.node:get_parent(); if parent then Log.info(parent:get_name()) endReturns Node?
Node:get_children()
Section titled “Node:get_children()”Returns an array of all direct child nodes.
for _, child in ipairs(self.node:get_children()) do child:set_visible(false) endReturns Node[]
Node:add_tag(tag)
Section titled “Node:add_tag(tag)”Adds a tag (group) to the node; false when it already has it.
self.node:add_tag("enemies")tagNodeTag|string
Returns boolean
Node:remove_tag(tag)
Section titled “Node:remove_tag(tag)”Removes a tag (group) from the node; returns false when it did not have it.
local removed = self.node:remove_tag("enemies")tagNodeTag|string
Returns boolean removed
Node:has_tag(tag)
Section titled “Node:has_tag(tag)”Checks whether the node has the given tag (group).
if other:has_tag("player") then self:collect() endtagNodeTag|string
Returns boolean
Node:get_tags()
Section titled “Node:get_tags()”Returns an array of all tags (groups) on the node.
for _, tag in ipairs(self.node:get_tags()) do Log.info(tag) endReturns string[]
Node:get_child(name)
Section titled “Node:get_child(name)”Finds a direct child node by its exact name.
local sprite = self.node:get_child("Sprite")nameNodeName|string
Returns Node?
Node:get_node(path)
Section titled “Node:get_node(path)”Finds a node by path relative to this one: “Gun”, “Body/Gun”, “../Player”, “.” (self).
local gun = self.node:get_node("Body/Gun")pathstringRelative node path
Returns Node? node The node, or nil if there is none
Node:add_child(child)
Section titled “Node:add_child(child)”Reparents a child node under this node.
local item = Scene.find_node("Key"); self.node:add_child(item)childNode
Node:remove_child(child)
Section titled “Node:remove_child(child)”Detaches a child node from this node.
self.node:remove_child(self.node:get_child("Shield"))childNode
Node:destroy()
Section titled “Node:destroy()”Removes this node and all its children from the active scene (at the end of the frame, so it’s safe from its own update).
self.node:destroy()Node:queue_free()
Section titled “Node:queue_free()”Removes this node and its children at the end of the frame (= destroy).
if self.health <= 0 then self.node:queue_free() endNode:connect(event, handler)
Section titled “Node:connect(event, handler)”Connects a handler to an event of this node (from any script). Handlers
are removed automatically when the connecting script or this node is
destroyed. A script also receives its own node’s events as methods named
on_<event> (e.g. function MyScript:on_timeout() end).
self.conn = timer:connect("timeout", function(value, source) self:fire() end)eventNodeEvent|ProjectEvent|stringEvent name (custom ones: the project’semitnames)handlerfun(value:any, source: Node) Called with the event value and this node
Returns integer id Connection id for disconnect
Node:disconnect(id)
Section titled “Node:disconnect(id)”Removes a connection made with connect.
local removed = timer:disconnect(self.conn)idintegerConnection id
Returns boolean removed
Node:emit(event, value)
Section titled “Node:emit(event, value)”Raises a custom event on this node: calls the node script’s on_<event>
method and every handler connected to that event name.
self.node:emit("health_changed", self.health)eventProjectEvent|stringEvent name (the project’s custom events complete)value?anyValue passed to handlers
Node:get_property(path)
Section titled “Node:get_property(path)”Reads an Inspector property by its path (vectors and colours as tables); “script.
local value = self.node:get_property("position")pathNodeProperty|string
Returns any
Node:set_property(path, value, y)
Section titled “Node:set_property(path, value, y)”Sets an Inspector property by its path: vectors as {x, y} or x, y; colours as {r, g, b[, a]} 0..1 or “#rrggbb[aa]”; enums by name; “script.
self.node:set_property("position", 100, 50)pathNodeProperty|stringvalueanyy?number
Node:set_shader(shader)
Section titled “Node:set_shader(shader)”Sets the node’s shader: a built-in or a project fragment shader (.fs). nil removes it.
self.node:set_shader("builtin:flash")shaderBuiltinShader|string|nil
Node:set_shader_param(name, x, y, z, w)
Section titled “Node:set_shader_param(name, x, y, z, w)”Sets a shader parameter (a uniform of the shader): a number, up to four numbers, a table {r, g, b, a} / {x, y}, or a texture path.
self.node:set_shader_param("amount", 0.8)namestringxnumber|number[]|stringy?numberz?numberw?number
Node:get_shader_param(name)
Section titled “Node:get_shader_param(name)”Gets a shader parameter (its value, else the shader’s default): up to four numbers, or the texture path.
local amount = self.node:get_shader_param("amount")namestring
Returns number|string|nil x, number? y, number? z, number? w
Node:set_blend_mode(mode)
Section titled “Node:set_blend_mode(mode)”Sets how the node is blended with what’s behind it.
self.node:set_blend_mode("additive")modeBlendMode
Node:get_script()
Section titled “Node:get_script()”The node’s script instance - the self its script sees: read or change its
fields and call its methods (enemy:get_script():take_damage(10)). nil
when the node has no script.
local enemy = Scene.find_node("Enemy"); enemy:get_script():take_damage(10)Returns table?
Node:set_paused(paused)
Section titled “Node:set_paused(paused)”Pauses this node and its children (except “always” ones).
Scene.find_node("Enemies"):set_paused(true)pausedboolean
Node:is_paused()
Section titled “Node:is_paused()”Checks whether the node is paused, by itself, a parent or the game.
if self.node:is_paused() then return endReturns boolean paused By itself, a parent or the game
Node:set_pause_mode(mode)
Section titled “Node:set_pause_mode(mode)”Sets how the node reacts to pausing: inherit from its parent, pausable, or always running.
self.node:set_pause_mode("always")mode"inherit"|"pausable"|"always"
Node:set_collision_layer(…)
Section titled “Node:set_collision_layer(…)”The collision layers this body’s shapes are on: project layer names (Project Settings > Physics), “LayerN” or numbers 1-16; several or a table.
self.node:set_collision_layer("player")...CollisionLayer|string|integer|table
Node:set_collision_mask(…)
Section titled “Node:set_collision_mask(…)”The collision layers this body’s shapes collide with.
self.node:set_collision_mask("world", "enemies")...CollisionLayer|string|integer|table
In a scene file
Section titled “In a scene file”{ "type": "Node", "name": "EmptyNode", "position": [ 0, 0 ]}