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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(animation): refresh replaced clips on paused sprites
yhh609c9cab0e3f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a3b469df0..45eaff59b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,8 @@ published separately; it ships inside the editor.### Fixed+- **Paused sprites refresh replaced animation clips.** A sprite that has already applied a clip follows a newly published clip while paused, updating its displayed frame without advancing the frame index or timer or firing playback events. Unchanged paused frames avoid component writes, and an initially paused animator still leaves the authored sprite untouched until playback or an explicit frame selection.+- **Empty and collapsed scroll views keep finite scrollbar geometry.** Thumb sizing handles zero content without dividing by zero and clamps the minimum thumb length to the available track. Clearing a list or collapsing its viewport no longer writes Infinity or NaN into native UI nodes, and tiny viewports keep their thumbs inside the track before normal sizing resumes on restore.- **Idle scrollbars stop forcing UI layout work.** Overlay thumbs write their node geometry only when position, length or units change, including during fade-out and after becoming invisible. Comparisons use the native float precision so fractional thumb sizes settle instead of dirtying layout every frame; scrolling and viewport/content resizing still refresh their geometry.diff --git a/sdk/src/animation/SpriteAnimator.ts b/sdk/src/animation/SpriteAnimator.tsindex 7449adb23..350cbc4c6 100644--- a/sdk/src/animation/SpriteAnimator.ts+++ b/sdk/src/animation/SpriteAnimator.ts@@ -242,7 +242,9 @@ export class SpriteAnimationAPI {if (!world.isEntityActive(entity)) continue;const animator = world.tryGet(entity, SpriteAnimator);if (!animator) continue;- if (!animator.enabled || (!animator.playing && !this.pendingApplies.has(animator)) || !animator.clip) continue;+ if (!animator.enabled || !animator.clip) continue;+ const applied = this.appliedAnimators.get(animator);+ if (!animator.playing && !this.pendingApplies.has(animator) && !applied) continue;const clipName = animator.clip;const clip = this.getClip(clipName);@@ -257,14 +259,15 @@ export class SpriteAnimationAPI {this.appliedAnimators.delete(animator);}+ let token = this.clipTokens.get(clip);+ if (!token) { token = {}; this.clipTokens.set(clip, token); }+ const needsInitialApply = this.appliedAnimators.get(animator) !== token;+ if (!animator.playing && !this.pendingApplies.has(animator) && !needsInitialApply) continue;// Speed scales EVERY frame's duration (not just the fps fallback), and// is guarded: 0/negative would otherwise freeze (Infinity) or run the// timer backward.const speed = Number.isFinite(animator.speed) ? Math.max(animator.speed, 1e-4) : 1;const fallback = 1 / (Number.isFinite(clip.fps) && clip.fps > 0 ? clip.fps : 12);- let token = this.clipTokens.get(clip);- if (!token) { token = {}; this.clipTokens.set(clip, token); }- const needsInitialApply = this.appliedAnimators.get(animator) !== token;animator.currentFrame = Number.isFinite(animator.currentFrame)? Math.max(0, Math.min(Math.floor(animator.currentFrame), clip.frames.length - 1)) : 0;const prevFrame = animator.currentFrame;diff --git a/sdk/tests/sprite-animation-activity-callback.test.ts b/sdk/tests/sprite-animation-activity-callback.test.tsindex 2ec309908..e5107e953 100644--- a/sdk/tests/sprite-animation-activity-callback.test.ts+++ b/sdk/tests/sprite-animation-activity-callback.test.ts@@ -21,6 +21,28 @@ function setup() {return { app, world, animation, spawn };}+it('refreshes a replaced clip while paused without advancing its frame or firing events', () => {+ const { app, world, animation, spawn } = setup(), entity = spawn();+ animation.update(world, 0.15);+ world.update(entity, SpriteAnimator, data => { data.playing = false; });+ const frame = world.get(entity, SpriteAnimator).currentFrame;+ const timer = world.get(entity, SpriteAnimator).frameTimer;+ const event = vi.fn(); animation.onEvent(entity, event);+ const clip = animation.getClip('walk')!;+ animation.registerClip({ ...clip, frames: [{ texture: 111 }, { texture: 222 }, { texture: 333 }] });+ animation.update(world, 1);+ expect(world.get(entity, Sprite).texture).toBe(222);+ expect(world.get(entity, SpriteAnimator).currentFrame).toBe(frame);+ expect(world.get(entity, SpriteAnimator).frameTimer).toBe(timer);+ expect(world.get(entity, SpriteAnimator).playing).toBe(false);+ expect(event).not.toHaveBeenCalled();+ const writes = vi.spyOn(world, 'set');+ for (let i = 0; i < 100; i++) animation.update(world, 1);+ expect(writes).not.toHaveBeenCalled();+ writes.mockRestore();+ app.quit();+});+it.each(['self', 'ancestor', 'component'] as const)('stops event dispatch and sprite writes when a callback disables %s', target => {const { app, world, animation, spawn } = setup(), entity = spawn();const parent = world.spawn();diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 3d730ac18..1e2964857 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): refresh replaced clips on paused sprites':+ { note: 'Paused sprites refresh replaced animation clips.' },'fix(ui): bound scrollbar geometry for empty viewports':{ note: 'Empty and collapsed scroll views keep finite scrollbar geometry.' },'perf(ui): avoid geometry writes for idle scrollbar thumbs':