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

/cocosair-assets

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Load asset URL textures, atlases and BMFont with AssetBank. Use for refcounted disposal, extension selection, cache reuse or AIR_E_ATLAS_IN_USE/AIR_E_FNT_IN_USE cleanup.

  • 10 files
  • 88.8 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-assets

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesquick-start.md

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

Derived from the cocosair-assets 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, DirectionalLight, MeshRenderer, Material, Vec3, Layers,
         Texture2D, ImageAsset, primitives, utils, assetManager, loadAssetAsync, isValid, AssetBank } from 'cocosair';

const app = await createAirApp({ canvas: '#GameCanvas' });   // #GameCanvas must exist before this import
const scene = new Scene('assets');
const camNode = new Node('Main');
scene.addChild(camNode); camNode.setPosition(new Vec3(0, 2, 6)); camNode.lookAt(new Vec3(0, 0, 0));
camNode.addComponent(Camera);
const lightNode = new Node('Key');
scene.addChild(lightNode); lightNode.setPosition(new Vec3(0, 8, 6)); lightNode.lookAt(new Vec3(0, 0, 0));
lightNode.addComponent(DirectionalLight);

// 1) no file involved: ImageAsset carries the CPU pixels, Texture2D is the GPU sampler
const imageAsset = new ImageAsset({
    width: 64, height: 64, _data: new Uint8Array(64 * 64 * 4).fill(120),
    _compressed: false, format: Texture2D.PixelFormat.RGBA8888,
});
const texture = new Texture2D();
texture.image = imageAsset;                    // equals mipmaps = [imageAsset]; clears other levels
// 2) Code First registry: the key you add is the path you load
assetManager.assets.add('gen/panel', texture);
const back = await loadAssetAsync('gen/panel', Texture2D);
console.log('roundtrip', back === texture, isValid(back));   // the registry is the cache
// 3) a runtime JSON file: fetch plus engine deserialize, plain-JSON fallback
console.log('manifest', await loadAssetAsync('assets/panel-manifest.json'));
// 4) refcounted remote bytes; ext is mandatory unless the URL already carries a suffix
const bank = new AssetBank();
const remote = await bank.load('/examples/tiledmap-basic/assets/tiles.png');   // -> ImageAsset
console.log('bank', remote.constructor.name, bank.refCount('/examples/tiledmap-basic/assets/tiles.png'));
// sample it (effect and property typing belong to cocosair-materials-effects)
const material = new Material();
material.initialize({ effectName: 'builtin-standard', defines: { USE_ALBEDO_MAP: true } });
material.setProperty('mainTexture', texture);
const cube = new Node('cube');
cube.layer = Layers.Enum.DEFAULT; cube.setPosition(new Vec3(0, 0.8, 0));
scene.addChild(cube);
const renderer = cube.addComponent(MeshRenderer);
renderer.mesh = utils.createMesh(primitives.box({ width: 1.6, height: 1.6, length: 1.6 }));
renderer.material = material;
app.run(scene);   // async render loop; first frame draws on a later tick, so never free synchronously here
// Release LATER (on teardown), in guard order; freeing now blanks the cube (its material still samples `texture`)
async function teardown() {
    renderer.material = null; material.destroy(); assetManager.assets.remove('gen/panel'); // unbind the sampler first
    assetManager.releaseAsset(texture); texture.destroy(); await bank.release('/examples/tiledmap-basic/assets/tiles.png'); // isValid flips false at frame end
}
</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
[
  "load remote files without a Creator resources bundle",
  "the same URL returns a destroyed asset",
  "create a texture from canvas or pixel data",
  "load a sprite atlas or bitmap font",
  "an atlas or font handle refuses to dispose"
]
owns
[
  "asset-bank",
  "asset-cache",
  "reference-counting",
  "texture2d",
  "atlas",
  "bmfont"
]
not_for
[
  "glTF or GLB model loading -> cocosair-gltf",
  "bind an existing font to Label -> cocosair-ui-2d",
  "live HTML textures and DOM -> cocosair-graphics-and-dom"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "管理远程资产、AssetBank 引用计数、纹理、图集和位图字体。用于加载、缓存、取消、共享资源释放或字体导入问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-assets