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

/cocosair-ui-2d

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Build Canvas UI with sprites, Label text, layout and widgets. Use for missing UI, viewport alignment, 2D draw order, BMFont binding or AIR_E_LABEL_WRAP.

  • 10 files
  • 39.1 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-ui-2d

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesquick-start.md

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

Derived from the cocosair-ui-2d 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.

Environment: the HTML examples using /build/ require the AIR development server and an existing bundle. In npm applications use the installed package name and the application's own bundler/server; resolve docs and declarations from that package. Do not copy repository URLs into a consumer app. Browser behavior is verified only for explicitly tested snippets and candidates.

Quick Start

<canvas id="GameCanvas"></canvas>
<script type="importmap">
  { "imports": { "cocosair": "/build/cocosair.module.js" } }
</script>
<script type="module">
import { createAirApp, Scene, Node, UITransform, Sprite, Label, Layers, view, ResolutionPolicy,
         ImageAsset, Texture2D, SpriteFrame, Color, createUICanvas, spriteNode, labelNode } from 'cocosair';

const app = await createAirApp({ canvas: '#GameCanvas' });   // #GameCanvas must exist before this import
view.setDesignResolutionSize(window.innerWidth, window.innerHeight, ResolutionPolicy.EXACT_FIT);
const scene = new Scene('ui');

// 1) Canvas + fullscreen Widget + ortho UI camera. createUICanvas sets node.layer,
//    camera.visibility and canvas.cameraComponent consistently to Layers.Enum.UI_2D.
const canvasNode = createUICanvas(scene, 'UICanvas', { designWidth: 1280, designHeight: 720 });

// 2) A panel with a runtime-generated frame (AIR has no image asset pipeline).
function solidFrame (cssColor) {
    const cvs = document.createElement('canvas'); cvs.width = 16; cvs.height = 16;
    const ctx = cvs.getContext('2d'); ctx.fillStyle = cssColor; ctx.fillRect(0, 0, 16, 16);
    const tex = new Texture2D(); tex.image = new ImageAsset(cvs);
    const sf = new SpriteFrame(); sf.texture = tex; return sf;
}
const panel = spriteNode(canvasNode, 'Panel', { size: [360, 120], position: [0, 40] });
const sprite = panel.getComponent(Sprite);
sprite.sizeMode = Sprite.SizeMode.CUSTOM;              // already CUSTOM from spriteNode; set before the frame
sprite.spriteFrame = solidFrame('#3478f6');

// 3) A label child of that panel; labelNode inherits the UI_2D layer and uses the system font.
labelNode(panel, 'Hello Cocos AIR', 'Title', { fontSize: 32, position: [0, 8], color: Color.WHITE });

// 4) Sorting2D on the panel pushes it behind later siblings via the UIRenderer priority it writes.
app.run(scene);                       // async render loop: frame 1 lands on a later tick
function teardown() { canvasNode.destroy(); }   // release later, never inline right after run
</script>

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
[
  "put sprites, labels or controls on screen",
  "UI renders nothing despite visible nodes",
  "widgets must realign after a viewport change",
  "bind an existing bitmap font to Label",
  "2D sprites and labels overlap in the wrong order"
]
owns
[
  "ui-canvas",
  "sprite-label",
  "widget-layout",
  "ui-controls",
  "font-binding",
  "sorting-2d"
]
not_for
[
  "load or parse a bitmap font -> cocosair-assets",
  "sprite masks and DOM overlays -> cocosair-graphics-and-dom",
  "native input and action mapping -> cocosair-input-action"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "使用 Canvas、布局、控件、Label、位图字体和二维排序。用于 UI 构建、文本显示或交互布局问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-ui-2d