Skip to content

cocos

Walk the cocos2d scene graph. Installed by the ffi capability on cocos games only. It fronts the engine’s existing node walk with metatables; it does not add a scene API the engine does not have.

cocos.scene(): node|nil

The current scene’s root node, or nil.

cocos.running_scene(): node|nil

The running scene’s root node, or nil.

Method Returns Description
n:name() string The node’s name.
n:children() node[] Its child nodes.
n:child(name) node nil
n:position() number, number x, y.
n:visible() boolean Whether it is visible.
n:pointer() pointer Its address, for memory / reflect.
n:field(...) field handle Delegates to the reflect cocos handle so raw fields stay reachable.
local root = cocos.running_scene()
for _, child in ipairs(root:children()) do
client.log(child:name())
end