Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(animation): complete immediate value tweens safely

yhh0ceec473b755
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ff3d9f13f..460912e58 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Immediate value tweens produce their endpoint.** Non-positive durations complete at the next eligible update, matching native tweens instead of emitting NaN or retaining a negative-duration tween forever. Delays and callback playback controls continue to apply.
+
- **Value tween callbacks preserve playback control.** Callback-created tweens start on the next update, recursive updates cannot advance the same pass twice, and callback cancellation or pause is not overwritten by completion or sequence handoff. Existing sequence members still resume in the same frame, without allocating a snapshot of the tween map.
- **Animation callbacks respect entity activity immediately.** Disabling an animator, entity or ancestor during a frame event stops remaining callbacks and sprite writes; later entries disabled by an earlier callback keep their playback position. Re-enabling applies deferred geometry without replaying handled events or restarting a completed one-shot.
diff --git a/sdk/src/animation/ValueTween.ts b/sdk/src/animation/ValueTween.ts
index 1814afcd5..1ddfd0f4d 100644
--- a/sdk/src/animation/ValueTween.ts
+++ b/sdk/src/animation/ValueTween.ts
@@ -128,7 +128,7 @@ export class ValueTweenManager {
}
entry.elapsed += step;
- const t = Math.min(entry.elapsed / entry.duration, 1);
+ const t = entry.duration > 0 ? Math.min(entry.elapsed / entry.duration, 1) : 1;
const easedT = applyEasing(entry.easing, t, entry.bezierPoints ?? undefined);
entry.callback(entry.from + (entry.to - entry.from) * easedT);
if (entry.state !== TweenState.Running) continue;
diff --git a/sdk/tests/value-tween.test.ts b/sdk/tests/value-tween.test.ts
index 7bb80423d..d70dcc1eb 100644
--- a/sdk/tests/value-tween.test.ts
+++ b/sdk/tests/value-tween.test.ts
@@ -25,6 +25,23 @@ function makeManager(cppState: () => number = () => TweenState.Running) {
}
describe('ValueTweenManager progression', () => {
+ it.each([0, -1])('completes an immediate tween of duration %j without emitting NaN', duration => {
+ const m = makeManager(), seen = vi.fn();
+ const id = m.create(10, 30, duration, seen);
+ m.update(0);
+ expect(seen.mock.calls).toEqual([[30]]);
+ expect(m.getState(id)).toBe(TweenState.Completed);
+ });
+
+ it('honors the delay before applying an immediate tween', () => {
+ const m = makeManager(), seen = vi.fn();
+ const id = m.create(10, 30, 0, seen, { delay: .5 });
+ m.update(.25);
+ expect(seen).not.toHaveBeenCalled();
+ m.update(.25);
+ expect(seen.mock.calls).toEqual([[30]]);
+ expect(m.getState(id)).toBe(TweenState.Completed);
+ });
it('does not recursively step the native engine through TweenAPI.update', () => {
const nativeStep = vi.fn();
const api = new TweenAPI({ anim_updateTweens: nativeStep } as unknown as AnimCore, {} as CppRegistry);
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 7ca9a2454..b733dfff5 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(animation): complete immediate value tweens safely':
+ { note: 'Immediate value tweens produce their endpoint.' },
'fix(animation): preserve value tween callback control':
{ note: 'Value tween callbacks preserve playback control.' },
'fix(animation): honor activity changes during frame callbacks':