Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-scene-graph

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Build Scene/Node hierarchies, Component lifecycles, layers and events. Use for reparenting, active inheritance, NodePool reuse, scene globals or resource release.

  • 10 files
  • 85.5 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-scene-graph

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescommon-mistakes.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Derived from the cocosair-scene-graph skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.

Common Mistakes

[HIGH] Expecting Creator asset URLs and Prefab data to resolve

Wrong:

import { Component, Prefab, instantiate, resources, SpriteFrame } from 'cocosair'; // same page alias as the Quick Start
class Enemy extends Component {
    bulletPrefab: Prefab = null;                 // nothing ever fills it: no Creator tool serializes .prefab
    fire () { instantiate(this.bulletPrefab); }  // instantiate runs on an always-null field
}
resources.load('enemies/goblin', SpriteFrame);   // rejects: no project resources bundle backs the URL

Correct:

import { Scene, Node, Component } from 'cocosair';
class Enemy extends Component {          // plain subclass; register by the class reference
    onLoad (): void { /* build children in code */ }
}
const node = new Node('Enemy');          // build the hierarchy programmatically
node.addComponent(Enemy);                 // addComponent(Enemy), not addComponent('Enemy')

AIR ships the Prefab/instantiate/resources classes but no Creator editor to serialize .scene/.prefab assets and no project resources bundle for Creator-style URLs to hit, so a Creator-parity load fails on the missing asset instead of falling back; reuse built subtrees through NodePool (node-ops.md), and a string component name in addComponent resolves only when that class was registered by name.

[HIGH] Assuming node.destroy() unsubscribes everything

Wrong:

class Ticker extends Component {
    taps = 0;
    onEnable () { input.on(Input.EventType.TOUCH_START, this.onTap, this); }
    // no onDisable off(); relies on destroy() cleaning it up -> stale listener on the global input
    onTap () { this.taps++; }   // taps keep rising after the scene switch: destroy() never touched input.on
}

Correct:

class Ticker extends Component {
    onEnable ()  { input.on(Input.EventType.TOUCH_START, this.onTap, this); }
    onDisable () { input.off(Input.EventType.TOUCH_START, this.onTap, this); } // explicit off
    onTap () { /* ... */ }
}
const ticker = new Ticker();
const other = scene.getChildByName('Other')!;
other.on(NodeEventType.TOUCH_END, ticker.onTap, ticker); // a callback on ANOTHER node, bound to this target
other.targetOff(ticker);                                 // release it by hand; destroying the Ticker node never does

destroy() only clears the node's own on/once listeners inside the deferred _destroyImmediate, and even that lands at end of frame (isValid stays true until then - unless the switch's runSceneImmediate purges the queue in the same call, see Contracts); input.on, DOM listeners, director/game events and callbacks bound on other nodes are never touched, so a scene switch leaks them.

[MEDIUM] Mutating layer bits by hand instead of the registration path

Wrong:

Layers.Enum.MyUi = 1 << 25;              // collides with reserved UI_2D bit and skips the enum update
node.layer = node.layer | (1 << 28);     // bit 28 is reserved (PROFILER)
camera.visibility = 1 << 20;             // a single reserved bit: DEFAULT and every other layer fails the 3D containment test and is culled

Correct:

Layers.addLayer('MyUi', 5);              // user bits only (0-19); 20-31 are reserved
node.layer = Layers.Enum.MyUi;
camera.visibility = Layers.makeMaskInclude([Layers.Enum.DEFAULT, Layers.Enum.MyUi]);

addLayer writes both Layers.Enum and Layers.BitMask and rejects bits outside 0-19; hand-setting reserved bits silently breaks the profiling and UI culling channels, and a single-bit replacement mask leaves the camera matching only that bit, so every other node goes unseen. IGNORE_RAYCAST is a ray-picking convention, not a hide-from-camera bit (the default camera mask still includes bit 20, and physics raycast masks use PhysicsGroup bits rather than node.layer): layers.md.

[MEDIUM] Reading world scale as the value you set

parent.setScale(new Vec3(2, 2, 2));
child.setScale(new Vec3(1, 1, 1));
console.log(child.scale);                // (1,1,1) local, exactly what you set
console.log(child.worldScale);           // (2,2,2) = parent world scale * local scale, not (1,1,1)

setScale writes LOCAL scale; worldScale multiplies up the parent chain (setting world scale back-solves local), so a child under a scaled or non-uniformly scaled parent renders and lights differently than its local value suggests. Arithmetic rows: node-ops.md.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "attach or reparent nodes in a scene",
  "understand component lifecycle and update order",
  "a child is inactive or inherits unexpected scale",
  "manage node events, layers or object pools",
  "release scenes and external listeners without leaking"
]
owns
[
  "scene-hierarchy",
  "component-lifecycle",
  "node-events",
  "layers",
  "node-pool",
  "scene-globals"
]
not_for
[
  "native input and action mapping -> cocosair-input-action",
  "app-level scene replacement -> cocosair-application",
  "camera framing and projection -> cocosair-camera"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "使用原生 Scene、Node、Component 构建场景树并管理层、事件、生命周期和资源释放。用于节点组织、组件更新、对象池或场景配置。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-scene-graph