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

/cocosair-graphics-and-dom

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Draw Graphics/SVG shapes and sprite masks; align a DOM overlay with UI/canvas nodes. Use for overlay placement, input interception, experimental HTML textures or AirUIMesh.

  • 15 files
  • 61.1 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-graphics-and-dom

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesquick-start.md

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

Derived from the cocosair-graphics-and-dom 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, Camera, Graphics, Layers, UITransform, Canvas, Color,
         view, ResolutionPolicy, drawAirGraphics, airGraphicsCommandsToSvg,
         rasterizeAirGraphics, createAirTextureSprite } from 'cocosair';

const app = await createAirApp({ canvas: '#GameCanvas' }); // #GameCanvas must exist first
view.setDesignResolutionSize(1280, 720, ResolutionPolicy.EXACT_FIT);
const scene = new Scene('graphics');
const UI = Layers.Enum.UI_2D;                              // the layer bit is on Layers.Enum; Layers.UI_2D is undefined
const ui = new Node('UI'); ui.layer = UI;
ui.addComponent(UITransform).setContentSize(1280, 720);
const canvasComponent = ui.addComponent(Canvas);          // UI renderers draw through their Canvas camera
scene.addChild(ui);
const camNode = new Node('UICamera'); camNode.layer = UI; camNode.setPosition(0, 0, 1000);
ui.addChild(camNode);
const cam = camNode.addComponent(Camera);
cam.projection = Camera.ProjectionType.ORTHO; cam.visibility = UI;
cam.clearColor = new Color(24, 30, 44, 255);
canvasComponent.cameraComponent = cam;

// 1) Solid commands replayed on a native Graphics component (Y up, node-centred).
const g = ui.addComponent(Graphics);
drawAirGraphics(g, [
    { op: 'rect', args: [-420, -140, 200, 100] },
    { op: 'fill', paint: { color: '#ff0000' } },
]);
const svg = airGraphicsCommandsToSvg(
    [{ op: 'rect', args: [0, 0, 100, 50] }, { op: 'fill', paint: { color: '#ff0000' } }],
    { x: 0, y: 0, width: 100, height: 50 });

// 2) Rich fills (gradient/pattern/hole) rasterize into a native Texture2D, then display.
const paint = rasterizeAirGraphics(
    [{ op: 'rect', args: [0, 0, 200, 100] },
     { op: 'fill', paint: { kind: 'linear', from: [0, 0], to: [200, 0],
       stops: [{ offset: 0, color: '#ff0000' }, { offset: 1, color: '#0000ff' }] } }],
    { bounds: { x: 0, y: 0, width: 200, height: 100 }, resolution: 2 });
const display = createAirTextureSprite(ui, paint.texture, { size: [200, 100] });
display.node.setPosition(140, 0, 0);

app.run(scene); // first frame draws on a later tick; never tear down inline here

function teardown() {
    display.dispose();   // owned node/SpriteFrame first, borrowed texture untouched
    paint.dispose();     // destroy the raster Texture2D after its display
    g.clear();
}
</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
[
  "draw shapes or export curves as SVG",
  "paint gradients, patterns or evenodd holes",
  "mask a sprite or inherit subtree blending",
  "keep a DOM input attached to a UI node",
  "display live HTML or warp textured UI geometry"
]
owns
[
  "graphics-svg",
  "rich-fills",
  "sprite-masks",
  "ui-blend",
  "dom-overlay",
  "html-texture"
]
not_for
[
  "UI widgets and layout -> cocosair-ui-2d",
  "keyboard focus and action routing -> cocosair-input-action",
  "general offscreen render targets -> cocosair-rendering"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "使用 Graphics、SVG、栅格填充、纹理显示、遮罩、混合和 DOM 覆盖层。用于绘图导出、富填充或实验性 HTML 纹理。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-graphics-and-dom