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

/cocosair-animation-tween

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Animate tweens and AnimationClip tracks with one step clock. Use to loop a sequence on a target, reverseTime, clean up playback or diagnose unavailable pose graphs.

  • 9 files
  • 52.5 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-animation-tween

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesstep-clock.md

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

Derived from src/air/step-clock.ts, tools/debug/probes/step-clock-probe/main.js, tools/verify/step-clock.cjs, build/cocosair.module.js, docs/manual/how-to-update-things.md, docs/evidence/examples-verified.json (as of 2026-10-10).

Why a step clock exists

game.step() only runs director.tick(fixedDT); it does not pause the main loop first, so calling it while the app is running means the real rAF pacer and your manual stepping advance the business clock at the same time - a dual clock, which the reliability task list forbids (src/air/step-clock.ts:1-19). createStepClock freezes the three-step contract so evidence capture is deterministic: begin() pauses the real clock, step(dt) advances exactly one frame and waits for it to be drawn, end() resumes.

The contract

createStepClock(options?) (src/air/step-clock.ts:62) reads frameRate = options.frameRate ?? 60 (:63) and stepTimeoutMs = options.stepTimeoutMs ?? 2000 (:64), and closes over stepping = false and stepped = 0 (:65-66). It returns an AirStepClock object literal (:77-108) with two getters and three methods:

Member Behavior Line
stepping (getter) whether begin() has run and end() has not src/air/step-clock.ts:78
stepped (getter) count of completed steps since begin() :79
begin() idempotent: returns if already stepping, else game.pause() and set stepping = true :80-84
step(dt = 1/frameRate) asserts paused, ticks one frame, resolves on AFTER_DRAW :85-102
end() idempotent: returns if not stepping, else clear the flag and game.resume() :103-107

step() is the guarded path. It first calls assertPaused() (:86), which reads the private game._paused and throws an Error whose message contains "dual clock" when the real clock is running (:68-75). It captures index = stepped + 1 (:87), then returns a Promise that arms a setTimeout(stepTimeoutMs) which removes the draw listener and rejects with no AFTER_DRAW within <n>ms (:89-92), registers a one-shot Director.EVENT_AFTER_DRAW listener that clears the timer, sets stepped = index and resolves { step: index, dt, afterDraw: true } (:93-98), and finally calls director.tick(dt) (:99-100). The timeout rejecting rather than silently resolving is deliberate (:54-55). begin()/end() map directly to game.pause()/game.resume(), which stop and restart the real pacer (rAF, render, business clock and audio) (:6-11).

The receipt type is AirStepFrame { step: number; dt: number; afterDraw: true } (src/air/step-clock.ts:24-31); the handle type is AirStepClock (:34-48) and the options type AirStepClockOptions { frameRate?; stepTimeoutMs? } (:51-56). createStepClock is Air-original with no upstream cocos4 counterpart (:18), and it is present in the runtime export block (build/cocosair.module.js, currently :161574).

Usage shape

const clock = createStepClock();      // frameRate 60, stepTimeoutMs 2000
clock.begin();                        // game.pause()
for (let i = 0; i < 90; i++) {
    const frame = await clock.step(1 / 60);   // frame == { step: i + 1, dt: 1/60, afterDraw: true }
    // read mid-values or hash the canvas here; the real clock is frozen
}
clock.end();                          // game.resume()

Because the real pacer is frozen between begin() and end(), a step(1/60) loop is frame-rate independent and reproducible: 90 steps accumulate exactly 1.5 s of business time regardless of wall clock. The single-clock rule and the dt discipline it protects are described in docs/manual/how-to-update-things.md.

Tooling

The probe that exercises this contract lives at tools/debug/probes/step-clock-probe/main.js; it is deliberately isolated under tools/debug/probes, is not registered in files.json, and does not enter the Gallery or coverage. It asserts six things: the dual-clock guard throws on a runtime step() without begin(), the real rAF is frozen after begin() (a 500 ms double-sample yields delta 0), 90 step(1/60) calls accumulate dt 1.5 s and an exact rotation angle, a mid-sequence value is non-endpoint, end() resumes the real clock, and two identical step sequences produce the same per-frame pixel sha256 (SwiftShader determinism). The runner is tools/verify/step-clock.cjs, invoked as NODE_PATH=<playwright> node tools/verify/step-clock.cjs; it serves the probe over a local HTTP server, launches headless Chromium with ANGLE/SwiftShader, waits for window.__stepProbe.ready, and is configured to write docs/evidence/w08-step-clock.json.

The evidence gap, stated plainly

createStepClock has ZERO apiProof bindings in docs/evidence/examples-verified.json (grep count 0), and no docs/evidence/w08-step-clock.json exists on disk anywhere in the repo, even though tools/verify/step-clock.cjs names it as its output. So the step clock is exported and probe-exercised but carries no committed, tracked evidence record: its proof is the passing probe and verifier, not a durable JSON artifact. Do not cite a w08 evidence file as if it were committed. By contrast, the tween and clip surfaces do carry bindings in examples-verified.json (tween frame-diff, Animation.play and AnimationClip verified) - see skills/cocosair-animation-tween/references/tween-ops.md and skills/cocosair-animation-tween/references/animation-clip.md. If you need a durable step-clock record, run the verifier and commit its output; until then treat the contract as source-proven and probe-proven only.

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
[
  "move or rotate a node over time",
  "a clip plays once instead of looping",
  "a tween will not reverse",
  "track classes fail to import by name",
  "step deterministic frames without a second live clock"
]
owns
[
  "tween",
  "animation-clip",
  "track-path",
  "wrap-mode",
  "step-clock",
  "pose-graph-limits"
]
not_for
[
  "glTF loading and instance setup -> cocosair-gltf",
  "skeletal binding and morph weights -> cocosair-skinning-morph",
  "scalar easing calculations -> cocosair-math"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "使用 AnimationClip、Animation 和 tween,管理播放模式、组合及单一时钟。用于动画播放、补间回收或确定性步进问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-animation-tween