Cocos AIR 2D UI contracts
Stop once you can answer the task. Do not read another same-topic reference for the same question.
Scope: Code-first Canvas hosts, UI cameras, layouts, widgets, fonts and 2D ordering.
Environment: use package imports in apps; source paths require an AIR checkout. See context.
Quick Start
For complete setup and teardown, read Quick Start.
Siblings: direct dependencies; reuse loaded skills.
Triggers
- Make UI visible with Canvas and its camera
- Create image panels with spriteNode
- Create labels with system or bitmap fonts
- Align widgets after a viewport resize
- Stack or grid children with Layout
- Wire buttons, sliders and scrolling
- Correct sprite or label overlap order
Exact API and symptom mappings: triggers.
Contracts
UI renderers need a Canvas, its orthographic camera and matching UI layer/visibility. Use createUICanvas to assemble this host. Label uses system fonts unless a supported single-page bitmap font is explicitly bound.
Read references/contracts.md only when the task needs exact option rules, limits, error behavior or source annotations. Prefer the topic references below for a narrower question.
Common Mistakes
- [HIGH] Label needs no Creator font-asset pipeline.
- [HIGH] Match UI layers and bind the Canvas camera.
- [MEDIUM] RichTextComponent and LabelAtlas are available.
- [MEDIUM] Set Sprite SizeMode.CUSTOM before assigning its frame.
Read relevant wrong/right examples before implementation.
Reference map
- Why is UI missing? - Canvas and layout
- Which interactive widget? - Components and aliases
- How does text render? - Fonts and wrapping
- Why is overlap wrong? - Layers and priority