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.

referencescontracts.md

≈1.1k 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.

Contracts

  • createUICanvas(scene, name = 'UICanvas', options = {}) returns the Canvas root Node, not a Canvas component (src/air/ui-kit.ts:37, :66). Defaults: layer = Layers.Enum.UI_2D (:38), designWidth = 1280 (:39), designHeight = 720 (:40). It adds UITransform sized to the design box with anchor (0.5, 0.5) (:44-46), Canvas (:47), and a Widget fully aligned to all four edges with alignMode = ON_WINDOW_RESIZE (:48-51).
  • The UI camera is a child node name + '/Camera', ORTHO, clearFlags = SOLID_COLOR, clearColor = new Color(24, 30, 44, 255), visibility = layer, near = 1, far = 2000, and the helper assigns canvas.cameraComponent = camera before returning (src/air/ui-kit.ts:54-66). Canvas.cameraComponent is a real setter that triggers _onResizeCamera() on change (src/cocos/2d/framework/canvas.ts:96-102); without it the batcher draws nothing.
  • Layer naming has two live conventions. The AIR helpers use Layers.Enum.UI_2D (bit 25, src/cocos/scene-graph/layers.ts:41), while examples/ui-components/main.js:49 and examples/ui-layout/main.js:36 use Layers.Enum.UI_3D (bit 23, src/cocos/scene-graph/layers.ts:39). Either works as long as the node's layer bit is included in the UI camera's visibility; the invariant is node layer == camera visibility layer, not a specific constant (docs/manual/2d-ui.md:56).
  • spriteNode(parent, name = 'Sprite', options) creates a UITransform + Sprite child with sizeMode = CUSTOM (src/air/ui-kit.ts:81-93). sizeMode must be CUSTOM before assigning a spriteFrame, or the node resizes to the texture (docs/manual/2d-ui.md:62-66). Runtime SpriteFrames come from document.createElement('canvas') -> ImageAsset -> Texture2D -> SpriteFrame; builtinResMgr.get('default-spriteframe') GPU-uploads fail in this build, so the examples generate frames instead (examples/ui-components/main.js:93).
  • labelNode(parent, text, name = 'Label', options) sets fontSize = 28 by default and lineHeight = Math.round(fontSize * 1.25) (src/air/ui-kit.ts:117, :124), color = options.color ?? Color.WHITE (:125), and only writes overflow/enableWrapText when supplied (:126-127). enableWrapText must be a boolean if present, else it throws Object.assign(new Error('[AIR_E_LABEL_WRAP] enableWrapText must be boolean'), { code: 'AIR_E_LABEL_WRAP' }) (src/air/ui-kit.ts:112-113).
  • The Label font surface is system + BMFont only. Label extends UIRenderer (src/cocos/2d/components/label.ts:180), Label.CacheMode is { NONE, BITMAP, CHAR } (:143, :149, :157, :164), and Label.Overflow is { NONE, CLAMP, SHRINK, RESIZE_HEIGHT } (:108, :114-133). Outlining and shadow are separate components LabelOutline (src/cocos/2d/components/label-outline.ts:46) and LabelShadow (src/cocos/2d/components/label-shadow.ts:43), not Label properties.
  • Every component in scope is on the single export { ... } block of build/cocosair.module.js (currently :161574). Canvas, Widget, Button, ScrollView, ProgressBar, Slider, Toggle, EditBox, PageView, SafeArea and BlockInputEvents are exported both bare and as ... as XComponent. Layout ships only as Layout$1 as Layout (src/cocos/ui/layout.ts:214), and RichText ships only as RichText as RichTextComponent with no bare RichText (src/cocos/2d/components/rich-text.ts:157); LabelAtlas is exported bare (src/cocos/2d/assets/label-atlas.ts:35).
  • 2D sorting: Sorting2D extends Component requires a UIRenderer (@requireComponent(UIRenderer), src/cocos/sorting/sorting-2d.ts:50-51), and sortingLayer/sortingOrder write uiRenderer.priority = SortingLayers.getSortingPriority(layerIndex, order) (:115-126, src/cocos/sorting/sorting-layers.ts:64-66). Out of the box SortingLayers.Enum has only default: 0; more layers arrive from settings through SortingLayers.init() (src/cocos/sorting/sorting-layers.ts:36-41). Intersection2D is a static 2D geometry intersection utility (src/cocos/physics-2d/builtin/intersection-2d.ts:301), not part of the sort pipeline despite being grouped with it on the export list.

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