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.

referencescontext.md

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

Working context

Use package imports and shipped docs for an application; use source paths and repository commands only in a confirmed AIR checkout. A copied host skill is not a runtime installation.

Read the shared environment rules when locating these roots. If sibling resources are unavailable, use the installed canonical chapter and disclose the limitation. Tool declarations identify workflow capabilities; they do not authorize installation, writes, publication or any action outside the user and host scope.

Related skills

  • cocosair - routing and shared Code First constraints; reuse it if already loaded.
  • cocosair-scene-graph - deferred destroy(), parenting order and Node.layer, which every UI node depends on.
  • cocosair-camera - Camera projection, visibility and clear color, the half of a Canvas that makes UI pixels appear.
  • cocosair-assets - Texture2D/SpriteFrame ownership and loadBitmapFont for authored faces.
  • cocosair-graphics-and-dom - Graphics, masks and the DOM overlay path for text that must stay selectable.
  • cocosair-performance - 2D batching and atlas behavior behind draw-order and label cache-mode choices.
  • cocosair-verification - the browser probes and gates behind the click and layout claims quoted below.

Original entry guidance

The original entry wording below is an on-demand archive, not a second routing source.

Use the environment rules to locate the checkout or installed package; sibling skills are optional direct dependencies, not a recursive load list.

Assemble a Canvas and its ortho UI camera from code, add sprites, labels and interactive widgets, and control 2D draw order - no Prefab, no Editor, no parallel UI abstraction.

Read references/quick-start.md when constructing the minimal example. It preserves the complete setup and teardown sequence; select the source-checkout or npm-consumer environment first.

Read references/context.md to select the owner of this step and only its directly needed dependencies. Reuse already loaded skills; this is not a recursive load list.

Original mistake navigation

Before implementing the relevant path, read its wrong/right examples in references/common-mistakes.md:

  • [HIGH] Waiting on a Creator font-asset pipeline for Label
  • [HIGH] Leaving the UI layer unset or the camera unbound
  • [MEDIUM] Reading the manual as "RichText and LabelAtlas are unavailable"

Original metadata

Description and description_en

The two original fields contained exactly the same value, retained once here.

Drives code-first 2D UI in the Cocos AIR runtime - createUICanvas (Canvas plus fullscreen Widget plus an ortho UI camera bound through canvas.cameraComponent, defaults designWidth 1280, designHeight 720, layer Layers.Enum.UI_2D), the spriteNode and labelNode helpers and their real defaults (fontSize 28, lineHeight Math.round(fontSize*1.25), the AIR_E_LABEL_WRAP guard), the widget components Canvas, Widget, Layout (exported as Layout$1 as Layout), Button, ScrollView, ProgressBar, Slider, Toggle, EditBox, PageView, SafeArea and BlockInputEvents, each also aliased as ...Component, Label system-font and BMFont binding, LabelOutline, LabelShadow, LabelAtlas, the RichText-only-as-RichTextComponent alias, and 2D draw order through SortingLayers, Sorting2D and the Intersection2D utility. Use when a UI node renders nothing, when text needs a font without any Creator font-asset pipeline, when widgets must realign on a viewport change, or when 2D sprites and labels stack in the wrong order.

Keywords

Cocos AIR, cocosair.js, ui, 2d

References

  • canvas-widget-layout.md - the createUICanvas assembly contract, Canvas.cameraComponent, Widget alignment modes and viewport relayout, Layout type/resizeMode/direction, and design resolution.
  • widgets.md - the component catalog with bare versus ...Component aliases, Layout$1 as Layout, base-class relationships, and the node.on('click', ...) event surface.
  • label-and-text.md - system font versus BMFont binding, Overflow and CacheMode semantics, LabelOutline/LabelShadow, LabelAtlas, RichText as an alias only, and the labelNode defaults and AIR_E_LABEL_WRAP.
  • sorting.md - SortingLayers.Enum, Sorting2D priority writing, and why Intersection2D is a geometry helper rather than a sorter.

Canonical docs

  • docs/manual/2d-ui.md - open for Canvas and UI-camera assembly, the runtime SpriteFrame path, sizeMode ordering, makeUINode, and resolution policy.
  • docs/manual/ui-layout-and-interaction.md - open for Button events, Widget relayout on resize, Layout auto-placement, and the two-viewport geometry verification note.
  • docs/manual/creating-text.md - open for the three text routes, Label defaults, the overflow semantics matrix, and the font-capability boundary.
  • docs/manual/bitmap-font-loading.md - open for parseFnt/createBitmapFont/loadBitmapFont, page-texture constraints, and the AIR_E_FNT_* errors.

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