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.

referencestexture-sprite.md

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

Derived from src/air/texture-sprite.ts and docs/manual/graphics-and-dom.md (as of 2026-10-10)

Texture sprites with anchor control

createAirTextureSprite(parent, texture, options) builds a native UI node that displays a borrowed TextureBase. The helper owns the created Node and SpriteFrame but never owns or mutates the texture's metadata (src/air/texture-sprite.ts:14-15, docs/manual/graphics-and-dom.md:10-17).

Signature and defaults

const image = createAirTextureSprite(parent, texture, {
    name?: string,                 // default 'TextureSprite'
    size?: [w, h],                 // default is the texture's own dimensions
    anchor?: [ax, ay],             // default [0.5, 0.5]
});

The anchor is written to the node's UITransform via setAnchorPoint, never onto the shared TextureBase (src/air/texture-sprite.ts:18, :25, docs/manual/graphics-and-dom.md:20). When size is omitted the node content size tracks the texture size on every refresh(); an explicit size stays fixed (src/air/texture-sprite.ts:23, :40). Invalid inputs (a texture with zero width/height, non-finite anchors, or non-positive sizes) throw AIR_E_TEXTURE_SPRITE_OPTIONS (src/air/texture-sprite.ts:19-20).

Borrowed textures

A RenderTexture or createAirRenderTarget().texture can be borrowed the same way; release the display object before releasing the target you borrowed from, because the caller keeps ownership of the texture for its whole lifetime (docs/manual/graphics-and-dom.md:20, src/air/rendering/render-target.ts:290).

refresh()

image.refresh();   // after resizing the underlying texture

refresh() recomputes the frame rect and originalSize from the current texture dimensions, rebinds spriteFrame through the native setter so the Sprite invalidates its cached texture and descriptor even when the identities are unchanged, releases stale descriptor-set caches, and, when no explicit size was set, resizes the node content box (src/air/texture-sprite.ts:28-41). Call it whenever the texture's dimensions change - for example after rasterizeAirGraphics uploads at a new size (docs/manual/graphics-and-dom.md:15). Calling it after dispose throws AIR_E_TEXTURE_SPRITE_DISPOSED (src/air/texture-sprite.ts:29).

dispose()

image.dispose();   // destroys the owned SpriteFrame and Node; leaves the borrowed texture alive

dispose() clears the sprite frame reference, destroys the owned SpriteFrame, and destroys the owned node if still valid - it does not destroy the borrowed texture, which stays the caller's responsibility (src/air/texture-sprite.ts:43-47).

Full lifecycle

const image = createAirTextureSprite(parent, texture, { size: [320, 180], anchor: [0, 1] });
// ... texture resized externally ...
image.refresh();
// ... later, during teardown, before releasing the texture ...
image.dispose();

See raster.md for the raster path that produces a texture to display, and sprite-mask.md for masking a Sprite display. For the runnable anchor/resize proof, see examples/dom-overlay-texture/src/main.ts (examples/dom-overlay-texture/src/main.ts:1).

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