Nodes
For overlap checks between instances and colliders, see Collision (hasCollided).
Enable / Visible Lifecycle Callbacks
Node files can optionally define lifecycle methods. Each method is called once per state change:
onEnabled(self)— called whenenablechanges fromfalsetotrueonDisabled(self)— called whenenablechanges fromtruetofalseonShown(self)— called whenvisiblechanges fromfalsetotrueonHidden(self)— called whenvisiblechanges fromtruetofalse
If you set the same value again (for example self.enable = true when it is already true), the callback is not fired.
All node instances have:
enable— controls whether the node runs. Ifenableisfalse, the node stays in memory but no lifecycle/update/draw methods run, andinit(self, ...)is deferred until the node becomes enabled.visible— controls whether the node is drawn. Whenvisibleisfalse,draw()/drawUI()(and any default sprite draw) are skipped.
spawn
Spawn a node instance from a node class table and pass extra args to init (e.g. spawn(ball, 10, 20)).
- spawn(classTable, ...) -> table
Parameters
- classTable — The node’s class table (global for that script, e.g. Player).
- ... — Extra values passed to the node’s init.
Returns
- table
Examples
-- Create a Player at (10, 20). Those two numbers are passed to its init.
local player = spawn(Player, 10, 20)destroy
Destroy a node instance and remove it from the game. For map placements (including no-script handles from collision / tag queries), turns off `enabled` and `visible` so collision checks and the collider overlay treat it as gone.
- destroy(node) -> bool
Parameters
- node — The node instance to destroy.
Returns
- bool
Examples
-- Remove the player node from the game.
destroy(player)getAllEntities
Return the scripted nodes currently in the game. Pass a type name such as `"Coin"` for that type, or a tag such as `tag.wall` to also include matching no-script map placements (with `isType` / `destroy`).
- getAllEntities() -> table
- getAllEntities(tagId) -> table
- getAllEntities(typeQuery) -> table
Parameters
- tagId — Collision tag (e.g. tag.wall).
- typeQuery — What type to look for (path, name, class, or instance).
Returns
- table
Examples
-- Every scripted node currently in the game.
local all = getAllEntities()
-- Every Coin instance (short type name or path).
local coins = getAllEntities("Coin")
-- Every map node tagged wall (scripted nodes and no-script placements).
local walls = getAllEntities(tag.wall)isType
Return true if this instance’s (or no-script map handle’s) type matches `query`. `query` may be a module path (e.g. `"entities/Coin.lua"`), a short type name, another instance, or a class table (the module global). Prefer `self:isType(query)`.
- isType(self, query) -> bool
Parameters
- self — This node instance.
- query — Type to compare (path, name, class, or instance).
Returns
- bool
Examples
-- Short type name, module path, or class table (module global).
local isCoin = isType(self, "Coin")
local isPlayer = player:isType("entities/Player.lua")
local alsoCoin = isType(other, Coin)