Cocos AIR asset triggers
Source annotations refer to the AIR checkout.
When to use what
- "load a JSON/manifest file at runtime" ->
loadAssetAsync(url)with no type argument (src/air/utils/load-asset.ts:38,:68-77). - "load something I built in code" ->
assetManager.assets.add(key, asset)thenloadAssetAsync(key, Type)(:60-62); seeexamples/ui-asset-loading/src/main.ts:339-342for the round-trip shape. - "load a png/jpg/audio/text by URL" ->
new AssetBank().load(url, { ext })for refcounted ownership, orassetManager.loadRemotewhen you accept the engine's URL cache (asset-bank.md). - "load a model" -> not this skill;
loadAssetAsyncroutes.gltf/.glbtoGLTFLoader(src/air/utils/load-asset.ts:40-43), see cocosair-gltf. - "texture from pixels without a file" ->
new ImageAsset(canvasElement)plustexture.image =(src/cocos/asset/assets/image-asset.ts:670,src/cocos/asset/assets/texture-2d.ts:161-163); to refill a level from a typed array,reset(info)thenuploadData(source, level)(texture2d.md). - "sprite sheets" ->
parseAtlasText/createAtlasHandlefor libGDX text atlases; Creator.plistatlases are not this parser's input (atlas.md). - "custom font" ->
loadBitmapFont(url, { bank })thenlabel.font = handle.font; the Creator TTF/font-asset workflow does not exist here (bmfont.md). - "the same URL hands back a destroyed asset, or a handle refuses to dispose" ->
assetManager.releaseAsset(asset)before re-loading and neverdestroy()alone (asset-bank.md);AIR_E_ATLAS_IN_USEandAIR_E_FNT_IN_USEboth mean someone still holds a reference, so detach the component first (atlas.md, bmfont.md). - "how do I know this actually works in a browser" -> the evidence column of each reference names the validator, not just the example id.