MCPcopy
hub / github.com/KilledByAPixel/LittleJS / tweenUpdate

Function tweenUpdate

plugins/tweenSystem.js:471–510  ·  view source on GitHub ↗

Engine plugin hook: advance every active tween by the appropriate delta. * Called once per render frame by the engine (no arguments). May also be * called explicitly with `(gameDelta, realDelta)` to drive tweens manually * — useful for headless tests or custom replay/scrubbing systems. * @pa

(gameDelta, realDelta)

Source from the content-addressed store, hash-verified

469 * @param {number} [realDelta] - Real-time delta in seconds; default: timeReal - lastTimeReal
470 * @memberof TweenSystem */
471function tweenUpdate(gameDelta, realDelta)
472{
473 if (gameDelta === undefined)
474 {
475 // Engine path: compute deltas from engine time globals.
476 gameDelta = time - lastTime;
477 realDelta = timeReal - lastTimeReal;
478 lastTime = time;
479 lastTimeReal = timeReal;
480 }
481 else if (realDelta === undefined)
482 {
483 // Manual path with one arg: real and game advance together.
484 realDelta = gameDelta;
485 }
486
487 // Iterate in reverse so removals don't disturb iteration.
488 for (let i = tweenActive.length; i--;)
489 {
490 const t = tweenActive[i];
491 if (t.paused) continue;
492 const dt = t.useRealTime ? realDelta : gameDelta;
493 if (dt <= 0) continue;
494
495 t.life -= dt;
496 if (t.life > 0)
497 {
498 t.callback(t.interp(t.life));
499 }
500 else
501 {
502 // Completion: fire end value, remove from active, fire then-callback.
503 t.callback(t.interp(0));
504 tweenActive.splice(i, 1);
505 const cb = t.thenCallback;
506 t.thenCallback = undefined;
507 if (cb) cb();
508 }
509 }
510}
511
512/** Stop every active tween and clear their then-callbacks. Useful for resets
513 * on level transitions or when changing scenes.

Callers 1

tween.test.mjsFile · 0.90

Calls 1

interpMethod · 0.80

Tested by

no test coverage detected