# 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

`cocos.scene()`: node|nil

The current scene's root node, or nil.

#### cocos.running_scene

`cocos.running_scene()`: node|nil

The running scene's root node, or nil.

## node userdata

Method | Returns | Description
--- | --- | ---
`n:name()` | string | The node's name.
`n:children()` | node[] | Its child nodes.
`n:child(name)` | node|nil | A named child.
`n:position()` | number, number | `x, y`.
`n:visible()` | boolean | Whether it is visible.
`n:pointer()` | pointer | Its address, for [memory](/base/memory/) / [reflect](/base/reflect/).
`n:field(...)` | field handle | Delegates to the [reflect](/base/reflect/) cocos handle so raw fields stay reachable.

```lua
local root = cocos.running_scene()
for _, child in ipairs(root:children()) do
  client.log(child:name())
end
```