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

/cocosair-2d-subsystems

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Build DragonBones, TiledMap, 2D/3D particles and billboards from runtime data. Use for raw asset strings, missing pixels, MotionStreak or Spine backend limits.

  • 12 files
  • 56.9 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-2d-subsystems

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesparticle-2d.md

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

Derived from src/cocos/particle-2d/particle-system-2d.ts, src/cocos/particle-2d/particle-asset.ts, src/cocos/particle-2d/particle-simulator-2d.ts, src/cocos/particle-2d/particle-system-2d-assembler.ts, src/cocos/particle-2d/motion-streak-2d.ts, src/cocos/particle-2d/index.ts, src/cocos/asset/asset-manager/parser.ts, src/cocos/gfx/base/define.ts, src/cocos/2d/framework/ui-renderer.ts, docs/notes/particle-2d-notes.md, build/cocosair.module.js (as of 2026-10-10).

What it does

ParticleSystem2D renders a ParticleSystem emitter tuned by an external plist, driven entirely at run time: the app generates or fetches the plist text, the engine parses it into a dictionary, and the component reads that dictionary when it applies its file. ParticleSystem2D, ParticleAsset and ParticleSystem2DAssembler reach the app through the single export { ... } block of build/cocosair.module.js (currently :161574). MotionStreak is the sibling renderer in the same module - a plain trailing ribbon, not a particle emitter.

The plist chain, end to end

Before attaching the emitter, create a Canvas component on its UI root, then assign the orthographic camera to that component's cameraComponent. UITransform does not create a Canvas; getComponent(Canvas) on a root with only UITransform returns null. Alternatively use createUICanvas from cocosair-ui-2d.

  1. assetManager.parser.parsePlist maps .plist input and fails with parse failed on malformed text (src/cocos/asset/asset-manager/parser.ts:63, :164-172).
  2. The parsed dictionary is attached as asset._nativeAsset; ParticleAsset itself declares only spriteFrame (src/cocos/particle-2d/particle-asset.ts:38-43), so the config never lives on the asset as named fields.
  3. custom = false plus a file assignment triggers _applyFile, which calls _initWithDictionary(file._nativeAsset) only in the non-custom branch (src/cocos/particle-2d/particle-system-2d.ts:922-948, guard :933-936).

Key dictionary and its silent-zero cases

  • The lifespan key is particleLifespan (src/cocos/particle-2d/particle-system-2d.ts:1047); assigning life in a plist does nothing. A missing lifespan makes life 0, which zeroes the emission clamp (:1055).
  • Set the startColorRed/Green/Blue/Alpha and finishColorRed/Green/Blue/Alpha values explicitly. _initWithDictionary defaults missing channels to zero; without startColorAlpha, particles can simulate with zero visible opacity.
  • emissionRate is re-clamped to totalParticles / life (src/cocos/particle-2d/particle-system-2d.ts:1055), so a large plist rate is silently capped.
  • blendFuncSource and blendFuncDestination are written straight into the gfx BlendFactor slots (src/cocos/particle-2d/particle-system-2d.ts:1062-1063), whose enum tops out at 14 (src/cocos/gfx/base/define.ts:505-521). The Creator plist values 770 and 1 land out of range, so the emitter simulates fully while drawing nothing. Override them via the inherited srcBlendFactor and dstBlendFactor accessors on UIRenderer (src/cocos/2d/framework/ui-renderer.ts:246-247), or keep the plist integers in the gfx slot range.

Determinism trio

loadRemote on a plist yields a bare Asset, so the parsePlist step is mandatory (docs/notes/particle-2d-notes.md:45). Cross-engine reproducibility needs all three of: a replaced random generator (math.setRandGenerator), manual simulator.step(dt) (src/cocos/particle-2d/particle-system-2d.ts:869-870, src/cocos/particle-2d/particle-simulator-2d.ts:344), and a pinned assembler.maxParticleDeltaTime, which is latched once from the frame time on the first assembler fetch (src/cocos/particle-2d/particle-simulator-2d.ts:349, src/cocos/particle-2d/particle-system-2d-assembler.ts:32, :47-48). Leaving any one out makes the count differ run to run.

MotionStreak sibling

There is no MotionStreak2D in the export block: the class is cc.MotionStreak (src/cocos/particle-2d/motion-streak-2d.ts:68, :73) re-exported as MotionStreak (src/cocos/particle-2d/index.ts:31-37). MotionStreak.texture is typed as a raw Texture2D (src/cocos/particle-2d/motion-streak-2d.ts:143), not a SpriteFrame, so feed it the wrapped texture directly.

Gotchas

  • custom = true makes _applyFile skip the whole dictionary mapping (src/cocos/particle-2d/particle-system-2d.ts:933-936); the emitter then runs only on your property assignments and ignores the plist.
  • Copying a Creator-exported plist verbatim carries blend values 770 and 1 (src/cocos/particle-2d/particle-system-2d.ts:1062-1063) into gfx slots that end at 14 (src/cocos/gfx/base/define.ts:505-521) - the classic "computes but renders no pixels" case.
  • Textures must be created after createAirApp; the gfx device is not ready before it and every frame warns on the sampler.

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
[
  "build DragonBones assets from raw JSON strings",
  "TiledMap edits do not redraw or resolve objects",
  "particles compute but render no pixels; createAirParticleSystem 3D emitters/trails CPU/GPU",
  "Spine skeleton stays blank without an error",
  "billboard or motion trail is invisible"
]
owns
[
  "dragonbones",
  "tiledmap",
  "particle-2d",
  "billboard",
  "motion-streak",
  "spine-limits"
]
not_for
[
  "basic UI layout and controls -> cocosair-ui-2d",
  "3D skeleton deformation -> cocosair-skinning-morph",
  "remote asset caching -> cocosair-assets"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "配置 Spine、DragonBones、TiledMap、二维粒子和 Billboard 的原生运行时契约。用于资源构造、空白画面或子系统能力边界问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-2d-subsystems