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
refactor(sdk): per-App SpriteAnimation (clips + listeners) (F3 B3b)
esengineb674bc3dc986
diff --git a/sdk/src/animation/AnimationPlugin.ts b/sdk/src/animation/AnimationPlugin.tsindex 30e89412c..8e27a6e1b 100644--- a/sdk/src/animation/AnimationPlugin.ts+++ b/sdk/src/animation/AnimationPlugin.ts@@ -10,7 +10,7 @@ import { Time, type TimeData } from '../resource';import type { Entity } from '../types';import type { ESEngineModule, CppRegistry } from '../wasm';import { Tween, TweenAPI } from './Tween';-import { spriteAnimatorSystemUpdate, removeAnimEventListeners } from './SpriteAnimator';+import { SpriteAnimation, SpriteAnimationApi } from './SpriteAnimator';import { playModeOnly } from '../env';import { SystemLabel } from '../systemLabels';@@ -22,11 +22,13 @@ export class AnimationPlugin implements Plugin {const registry = app.world.getCppRegistry() as CppRegistry;const tween = new TweenAPI(module, registry);app.insertResource(Tween, tween);+ const anim = new SpriteAnimationApi();+ app.insertResource(SpriteAnimation, anim);const world = app.world;world.onDespawn((entity: Entity) => {tween.cancelAll(entity);- removeAnimEventListeners(entity);+ anim.removeEntityListeners(entity);});app.addSystemToSchedule(Schedule.Update, defineSystem(@@ -38,9 +40,9 @@ export class AnimationPlugin implements Plugin {), { runIf: playModeOnly });app.addSystemToSchedule(Schedule.Update, defineSystem(- [Res(Time)],- (time: TimeData) => {- spriteAnimatorSystemUpdate(world, time.delta);+ [Res(Time), Res(SpriteAnimation)],+ (time: TimeData, animApi: SpriteAnimationApi) => {+ animApi.update(world, time.delta);},{ name: 'SpriteAnimatorSystem' }), { runAfter: [SystemLabel.Tween], runIf: playModeOnly });diff --git a/sdk/src/animation/SpriteAnimator.ts b/sdk/src/animation/SpriteAnimator.tsindex 3fc6e23a6..29109327e 100644--- a/sdk/src/animation/SpriteAnimator.ts+++ b/sdk/src/animation/SpriteAnimator.ts@@ -53,10 +53,10 @@ export function shouldFireEvent(eventFrame: number, prevFrame: number, newFrame:// =============================================================================/**- * Owns one App's sprite-animation clip registry and frame-event listeners, and- * advances SpriteAnimator components. Published as the {@link SpriteAnimation}- * resource (B3); a default instance backs the legacy free functions until the- * per-App flip (B3b) routes registration/listeners through the owning App.+ * Owns one App's sprite-animation clip registry and frame-event listeners,+ * advances SpriteAnimator components, and drives goto-frame/label. Published as+ * the {@link SpriteAnimation} resource; read it as+ * `app.getResource(SpriteAnimation)`.*/export class SpriteAnimationApi {private readonly clips = new Map<string, SpriteAnimClip>();@@ -187,32 +187,35 @@ export class SpriteAnimationApi {}}}++ // -- goto frame / label ---------------------------------------------------++ gotoFrame(animator: SpriteAnimatorData, frameIndex: number, andPlay: boolean = true): void {+ const clip = this.clips.get(animator.clip);+ if (!clip || clip.frames.length === 0) return;++ animator.currentFrame = Math.max(0, Math.min(frameIndex, clip.frames.length - 1));+ animator.frameTimer = 0;+ animator.playing = andPlay;+ }++ gotoLabel(animator: SpriteAnimatorData, label: string, andPlay: boolean = true): void {+ const clip = this.clips.get(animator.clip);+ if (!clip || !clip.labels) return;++ const frameIndex = clip.labels[label];+ if (frameIndex === undefined) return;++ this.gotoFrame(animator, frameIndex, andPlay);+ }}/*** Per-App sprite-animation resource (clip registry + frame-event listeners),- * published by `AnimationPlugin` (B3b). Read as `app.getResource(SpriteAnimation)`.+ * published by `AnimationPlugin`. Read as `app.getResource(SpriteAnimation)`.*/export const SpriteAnimation = defineResource<SpriteAnimationApi>(null!, 'SpriteAnimation');-// B3a: default instance backing the legacy free functions below (per-App in B3b).-const defaultAnim = new SpriteAnimationApi();--export function registerAnimClip(clip: SpriteAnimClip): void { defaultAnim.registerClip(clip); }-export function unregisterAnimClip(name: string): void { defaultAnim.unregisterClip(name); }-export function getAnimClip(name: string): SpriteAnimClip | undefined { return defaultAnim.getClip(name); }-export function clearAnimClips(): void { defaultAnim.clearClips(); }--export function onAnimEvent(entity: Entity, handler: SpriteAnimEventHandler): () => void {- return defaultAnim.onEvent(entity, handler);-}-export function onAnimEventGlobal(handler: SpriteAnimEventHandler): () => void {- return defaultAnim.onEventGlobal(handler);-}-export function removeAnimEventListeners(entity: Entity): void {- defaultAnim.removeEntityListeners(entity);-}-// =============================================================================// SpriteAnimator Component// =============================================================================@@ -238,42 +241,3 @@ export const SpriteAnimator: ComponentDef<SpriteAnimatorData> = defineComponent(}, {assetFields: [{ field: 'clip', type: 'anim-clip' }],});--// =============================================================================-// SpriteAnimator System-// =============================================================================--export function spriteAnimatorSystemUpdate(world: World, deltaTime: number): void {- defaultAnim.update(world, deltaTime);-}--// =============================================================================-// Goto Frame / Label-// =============================================================================--export function spriteAnimatorGotoFrame(- animator: SpriteAnimatorData,- frameIndex: number,- andPlay: boolean = true,-): void {- const clip = defaultAnim.getClip(animator.clip);- if (!clip || clip.frames.length === 0) return;-- animator.currentFrame = Math.max(0, Math.min(frameIndex, clip.frames.length - 1));- animator.frameTimer = 0;- animator.playing = andPlay;-}--export function spriteAnimatorGotoLabel(- animator: SpriteAnimatorData,- label: string,- andPlay: boolean = true,-): void {- const clip = defaultAnim.getClip(animator.clip);- if (!clip || !clip.labels) return;-- const frameIndex = clip.labels[label];- if (frameIndex === undefined) return;-- spriteAnimatorGotoFrame(animator, frameIndex, andPlay);-}diff --git a/sdk/src/animation/index.ts b/sdk/src/animation/index.tsindex 718c086d4..ccda275df 100644--- a/sdk/src/animation/index.ts+++ b/sdk/src/animation/index.ts@@ -29,21 +29,13 @@ export {export {SpriteAnimator,- spriteAnimatorSystemUpdate,- registerAnimClip,- unregisterAnimClip,- getAnimClip,- clearAnimClips,+ SpriteAnimation,+ SpriteAnimationApi,type SpriteAnimatorData,type SpriteAnimClip,type SpriteAnimFrame,type SpriteAnimEvent,type SpriteAnimEventHandler,- spriteAnimatorGotoFrame,- spriteAnimatorGotoLabel,- onAnimEvent,- onAnimEventGlobal,- removeAnimEventListeners,} from './SpriteAnimator';export {diff --git a/sdk/src/asset/AssetLoader.ts b/sdk/src/asset/AssetLoader.tsindex 1197f97b3..9df8b8333 100644--- a/sdk/src/asset/AssetLoader.ts+++ b/sdk/src/asset/AssetLoader.ts@@ -61,6 +61,11 @@ export interface LoadContext {* assets will fail to preload.*/getAudio(): import('../audio/Audio').AudioAPI | null;+ /**+ * Sprite-animation API for the owning app (clip registry), resolved lazily+ * like {@link getAudio}. Returns null when no AnimationPlugin is installed.+ */+ getSpriteAnimation(): import('../animation/SpriteAnimator').SpriteAnimationApi | null;}export interface AssetLoader<T> {diff --git a/sdk/src/asset/AssetPlugin.ts b/sdk/src/asset/AssetPlugin.tsindex 78ff4df68..874bb61db 100644--- a/sdk/src/asset/AssetPlugin.ts+++ b/sdk/src/asset/AssetPlugin.ts@@ -5,6 +5,7 @@ import { HttpBackend } from './Backend';import { initBuiltinAssetFields } from './AssetFieldRegistry';import { AssetRefCounter } from './AssetRefCounter';import { Audio, type AudioAPI } from '../audio/Audio';+import { SpriteAnimation, type SpriteAnimationApi } from '../animation/SpriteAnimator';import { log } from '../logger';export type AssetsData = AssetsClass;@@ -31,6 +32,8 @@ export class AssetPlugin implements Plugin {module,getAudio: (): AudioAPI | null =>app.hasResource(Audio) ? app.getResource(Audio) : null,+ getSpriteAnimation: (): SpriteAnimationApi | null =>+ app.hasResource(SpriteAnimation) ? app.getResource(SpriteAnimation) : null,});// Install the ref counter so resolveSceneAssetPaths records whodiff --git a/sdk/src/asset/Assets.ts b/sdk/src/asset/Assets.tsindex 54d44d5f6..8c96ffa58 100644--- a/sdk/src/asset/Assets.ts+++ b/sdk/src/asset/Assets.ts@@ -80,6 +80,7 @@ export interface AssetsOptions {* in any order. Pass null (or omit) if no audio support is needed.*/getAudio?: () => import('../audio/Audio').AudioAPI | null;+ getSpriteAnimation?: () => import('../animation/SpriteAnimator').SpriteAnimationApi | null;}export interface AssetBundle {@@ -132,6 +133,7 @@ export class Assets {private module_: ESEngineModule;private getAudio_: () => import('../audio/Audio').AudioAPI | null;+ private getSpriteAnimation_: () => import('../animation/SpriteAnimator').SpriteAnimationApi | null;private loaders_ = new Map<string, AssetLoader<unknown>>();private textureLoader_: TextureLoader;private textureImportResolver_: TextureImportSettingsResolver | null = null;@@ -151,6 +153,7 @@ export class Assets {this.catalog = options.catalog ?? Catalog.empty();this.module_ = options.module;this.getAudio_ = options.getAudio ?? (() => null);+ this.getSpriteAnimation_ = options.getSpriteAnimation ?? (() => null);this.textureLoader_ = new TextureLoader(options.module);this.spineLoader_ = new SpineAssetLoader(options.module);@@ -806,6 +809,9 @@ export class Assets {getAudio() {return self.getAudio_();},+ getSpriteAnimation() {+ return self.getSpriteAnimation_();+ },};return this.loadContext_;}diff --git a/sdk/src/asset/loaders/AnimClipAssetLoader.ts b/sdk/src/asset/loaders/AnimClipAssetLoader.tsindex 3d4dce21b..fc8888d0f 100644--- a/sdk/src/asset/loaders/AnimClipAssetLoader.ts+++ b/sdk/src/asset/loaders/AnimClipAssetLoader.ts@@ -1,6 +1,5 @@import type { AssetLoader, LoadContext, AnimClipResult } from '../AssetLoader';import { extractAnimClipTexturePaths, parseAnimClipData, type AnimClipAssetData } from '../../animation/AnimClipLoader';-import { registerAnimClip } from '../../animation/SpriteAnimator';import { log } from '../../logger';export class AnimClipAssetLoader implements AssetLoader<AnimClipResult> {@@ -25,7 +24,7 @@ export class AnimClipAssetLoader implements AssetLoader<AnimClipResult> {}const clip = parseAnimClipData(path, data, textureHandles);- registerAnimClip(clip);+ ctx.getSpriteAnimation()?.registerClip(clip);return { clipId: path };}diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.tsindex f615e00e2..b23f0f82d 100644--- a/sdk/src/core-content.ts+++ b/sdk/src/core-content.ts@@ -180,11 +180,8 @@ export {LoopMode,ValueTweenHandle,SpriteAnimator,- spriteAnimatorSystemUpdate,- registerAnimClip,- unregisterAnimClip,- getAnimClip,- clearAnimClips,+ SpriteAnimation,+ SpriteAnimationApi,AnimationPlugin,animationPlugin,type TweenOptions,@@ -197,9 +194,6 @@ export {parseAnimClipData,extractAnimClipTexturePaths,type AnimClipAssetData,- onAnimEvent,- onAnimEventGlobal,- removeAnimEventListeners,TweenGroup,TweenSequence,type Completable,diff --git a/sdk/src/runtimeLoader.ts b/sdk/src/runtimeLoader.tsindex 6c6e8d159..352e190b6 100644--- a/sdk/src/runtimeLoader.ts+++ b/sdk/src/runtimeLoader.ts@@ -20,7 +20,7 @@ import { getAssetTypeEntry } from './assetTypes';import { SceneManager, type SceneConfig } from './sceneManager';import { DEFAULT_GRAVITY, DEFAULT_FIXED_TIMESTEP } from './defaults';import { type AnimClipAssetData, extractAnimClipTexturePaths, parseAnimClipData } from './animation/AnimClipLoader';-import { registerAnimClip } from './animation/SpriteAnimator';+import { SpriteAnimation } from './animation/SpriteAnimator';import { Audio } from './audio/Audio';import { flushPendingSystems } from './app';import { updateCameraAspectRatio } from './scene';@@ -372,10 +372,12 @@ async function preloadAudioClips(app: App, provider: RuntimeAssetProvider, audio// =============================================================================async function loadAnimClips(+ app: App,module: ESEngineModule,provider: RuntimeAssetProvider,animClipPaths: Set<string>,): Promise<void> {+ const anim = app.hasResource(SpriteAnimation) ? app.getResource(SpriteAnimation) : null;for (const clipPath of animClipPaths) {try {const clipText = await provider.readText(clipPath);@@ -394,7 +396,7 @@ async function loadAnimClips(}const clip = parseAnimClipData(clipPath, clipData, textureHandles);- registerAnimClip(clip);+ anim?.registerClip(clip);} catch (err) {log.warn('runtime', `Failed to load animation clip: ${clipPath}`, err);}@@ -490,7 +492,7 @@ export async function loadRuntimeScene(options: LoadRuntimeSceneOptions): Promisconst fontCache = await loadBitmapFonts(module, provider, getAssetPathsByType(discovered, 'font'));const materialCache = await loadMaterials(provider, getAssetPathsByType(discovered, 'material'));- await loadAnimClips(module, provider, getAssetPathsByType(discovered, 'anim-clip'));+ await loadAnimClips(app, module, provider, getAssetPathsByType(discovered, 'anim-clip'));await loadTilemaps(module, provider, getAssetPathsByType(discovered, 'tilemap'));await preloadAudioClips(app, provider, getAssetPathsByType(discovered, 'audio'));diff --git a/sdk/tests/anim-clip-asset.test.ts b/sdk/tests/anim-clip-asset.test.tsindex 7c76b7d1a..2e27ff6c7 100644--- a/sdk/tests/anim-clip-asset.test.ts+++ b/sdk/tests/anim-clip-asset.test.ts@@ -4,11 +4,6 @@ import {getEditorType,isKnownAssetExtension,} from '../src/assetTypes';-import {- registerAnimClip,- getAnimClip,- clearAnimClips,-} from '../src/animation/SpriteAnimator';import {parseAnimClipData,extractAnimClipTexturePaths,@@ -70,10 +65,6 @@ describe('.esanim asset type', () => {// =============================================================================describe('parseAnimClipData', () => {- beforeEach(() => {- clearAnimClips();- });-it('should parse valid clip data', () => {const json: AnimClipAssetData = {version: '1.0',diff --git a/sdk/tests/sprite-animator-events.test.ts b/sdk/tests/sprite-animator-events.test.tsindex 1704f6537..a480dbe57 100644--- a/sdk/tests/sprite-animator-events.test.ts+++ b/sdk/tests/sprite-animator-events.test.ts@@ -1,19 +1,17 @@import { describe, it, expect, beforeEach, vi } from 'vitest';import {+ SpriteAnimationApi,type SpriteAnimClip,type SpriteAnimEvent,- registerAnimClip,- clearAnimClips,- onAnimEvent,- onAnimEventGlobal,- removeAnimEventListeners,} from '../src/animation/SpriteAnimator';import { shouldFireEvent } from '../src/animation/SpriteAnimator';describe('SpriteAnimator Frame Events', () => {+ let anim: SpriteAnimationApi;+beforeEach(() => {- clearAnimClips();+ anim = new SpriteAnimationApi();});describe('shouldFireEvent', () => {@@ -45,7 +43,7 @@ describe('SpriteAnimator Frame Events', () => {describe('onAnimEvent', () => {it('registers and removes listener', () => {const handler = vi.fn();- const unsub = onAnimEvent(1 as any, handler);+ const unsub = anim.onEvent(1 as any, handler);unsub();});});@@ -53,7 +51,7 @@ describe('SpriteAnimator Frame Events', () => {describe('onAnimEventGlobal', () => {it('registers and removes global listener', () => {const handler = vi.fn();- const unsub = onAnimEventGlobal(handler);+ const unsub = anim.onEventGlobal(handler);unsub();});});@@ -61,9 +59,9 @@ describe('SpriteAnimator Frame Events', () => {describe('removeAnimEventListeners', () => {it('removes all listeners for entity', () => {const handler = vi.fn();- onAnimEvent(1 as any, handler);- onAnimEvent(1 as any, handler);- removeAnimEventListeners(1 as any);+ anim.onEvent(1 as any, handler);+ anim.onEvent(1 as any, handler);+ anim.removeEntityListeners(1 as any);});});@@ -79,7 +77,7 @@ describe('SpriteAnimator Frame Events', () => {{ frame: 2, name: 'end', data: { sound: 'swoosh' } },],};- registerAnimClip(clip);+ anim.registerClip(clip);expect(clip.events).toHaveLength(2);expect(clip.events![0].name).toBe('hit');expect(clip.events![1].data).toEqual({ sound: 'swoosh' });diff --git a/sdk/tests/sprite-animator-goto.test.ts b/sdk/tests/sprite-animator-goto.test.tsindex c18a59ef6..f64c6ea88 100644--- a/sdk/tests/sprite-animator-goto.test.ts+++ b/sdk/tests/sprite-animator-goto.test.ts@@ -1,9 +1,6 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import {- registerAnimClip,- clearAnimClips,- spriteAnimatorGotoFrame,- spriteAnimatorGotoLabel,+ SpriteAnimationApi,type SpriteAnimClip,type SpriteAnimatorData,} from '../src/animation/SpriteAnimator';@@ -39,15 +36,17 @@ function createAnimatorData(): SpriteAnimatorData {}describe('SpriteAnimator goto', () => {+ let anim: SpriteAnimationApi;+beforeEach(() => {- clearAnimClips();- registerAnimClip(createTestClip());+ anim = new SpriteAnimationApi();+ anim.registerClip(createTestClip());});describe('gotoFrame', () => {it('should jump to specified frame', () => {const data = createAnimatorData();- spriteAnimatorGotoFrame(data, 2, true);+ anim.gotoFrame(data, 2, true);expect(data.currentFrame).toBe(2);expect(data.frameTimer).toBe(0);expect(data.playing).toBe(true);@@ -55,14 +54,14 @@ describe('SpriteAnimator goto', () => {it('should clamp to last frame', () => {const data = createAnimatorData();- spriteAnimatorGotoFrame(data, 99, false);+ anim.gotoFrame(data, 99, false);expect(data.currentFrame).toBe(3);expect(data.playing).toBe(false);});it('should stop when andPlay=false', () => {const data = createAnimatorData();- spriteAnimatorGotoFrame(data, 1, false);+ anim.gotoFrame(data, 1, false);expect(data.currentFrame).toBe(1);expect(data.playing).toBe(false);});@@ -71,7 +70,7 @@ describe('SpriteAnimator goto', () => {describe('gotoLabel', () => {it('should jump to named label', () => {const data = createAnimatorData();- spriteAnimatorGotoLabel(data, 'mid', true);+ anim.gotoLabel(data, 'mid', true);expect(data.currentFrame).toBe(2);expect(data.playing).toBe(true);});@@ -79,14 +78,14 @@ describe('SpriteAnimator goto', () => {it('should do nothing for unknown label', () => {const data = createAnimatorData();data.currentFrame = 1;- spriteAnimatorGotoLabel(data, 'nonexistent', true);+ anim.gotoLabel(data, 'nonexistent', true);expect(data.currentFrame).toBe(1);});it('should jump to start label', () => {const data = createAnimatorData();data.currentFrame = 3;- spriteAnimatorGotoLabel(data, 'start', false);+ anim.gotoLabel(data, 'start', false);expect(data.currentFrame).toBe(0);expect(data.playing).toBe(false);});diff --git a/sdk/tests/sprite-animator.test.ts b/sdk/tests/sprite-animator.test.tsindex a2b0a22a0..00e56a177 100644--- a/sdk/tests/sprite-animator.test.ts+++ b/sdk/tests/sprite-animator.test.ts@@ -5,13 +5,9 @@ import type { CppRegistry, ESEngineModule } from '../src/wasm';import type { Entity } from '../src/types';import {SpriteAnimator,+ SpriteAnimationApi,type SpriteAnimatorData,type SpriteAnimClip,- registerAnimClip,- unregisterAnimClip,- getAnimClip,- clearAnimClips,- spriteAnimatorSystemUpdate,} from '../src/animation/SpriteAnimator';function createAnimTestWorld(): { world: World; registry: CppRegistry } {@@ -50,11 +46,12 @@ function createAnimTestWorld(): { world: World; registry: CppRegistry } {describe('SpriteAnimator', () => {let world: World;+ let anim: SpriteAnimationApi;beforeEach(() => {const ctx = createAnimTestWorld();world = ctx.world;- clearAnimClips();+ anim = new SpriteAnimationApi();});// =========================================================================@@ -100,27 +97,27 @@ describe('SpriteAnimator', () => {};it('should register and retrieve a clip', () => {- registerAnimClip(testClip);- const retrieved = getAnimClip('walk');+ anim.registerClip(testClip);+ const retrieved = anim.getClip('walk');expect(retrieved).toEqual(testClip);});it('should return undefined for unregistered clip', () => {- expect(getAnimClip('nonexistent')).toBeUndefined();+ expect(anim.getClip('nonexistent')).toBeUndefined();});it('should unregister a clip', () => {- registerAnimClip(testClip);- unregisterAnimClip('walk');- expect(getAnimClip('walk')).toBeUndefined();+ anim.registerClip(testClip);+ anim.unregisterClip('walk');+ expect(anim.getClip('walk')).toBeUndefined();});it('should clear all clips', () => {- registerAnimClip(testClip);- registerAnimClip({ ...testClip, name: 'run' });- clearAnimClips();- expect(getAnimClip('walk')).toBeUndefined();- expect(getAnimClip('run')).toBeUndefined();+ anim.registerClip(testClip);+ anim.registerClip({ ...testClip, name: 'run' });+ anim.clearClips();+ expect(anim.getClip('walk')).toBeUndefined();+ expect(anim.getClip('run')).toBeUndefined();});});@@ -141,7 +138,7 @@ describe('SpriteAnimator', () => {};beforeEach(() => {- registerAnimClip(walkClip);+ anim.registerClip(walkClip);});it('should apply first frame texture on initial tick', () => {@@ -149,7 +146,7 @@ describe('SpriteAnimator', () => {world.insert(entity, Sprite, { texture: 0 });world.insert(entity, SpriteAnimator, { clip: 'walk' });- spriteAnimatorSystemUpdate(world, 0.001);+ anim.update(world, 0.001);const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(10);@@ -161,7 +158,7 @@ describe('SpriteAnimator', () => {world.insert(entity, SpriteAnimator, { clip: 'walk' });// fps=10, frameDuration=0.1s, dt=0.1 should advance one frame- spriteAnimatorSystemUpdate(world, 0.1);+ anim.update(world, 0.1);const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(20);@@ -172,7 +169,7 @@ describe('SpriteAnimator', () => {world.insert(entity, Sprite, { texture: 10 });world.insert(entity, SpriteAnimator, { clip: 'walk' });- spriteAnimatorSystemUpdate(world, 0.05);+ anim.update(world, 0.05);const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(10);@@ -184,9 +181,9 @@ describe('SpriteAnimator', () => {world.insert(entity, SpriteAnimator, { clip: 'walk' });// Advance through all 3 frames (3 * 0.1 = 0.3s)- spriteAnimatorSystemUpdate(world, 0.1);- spriteAnimatorSystemUpdate(world, 0.1);- spriteAnimatorSystemUpdate(world, 0.1);+ anim.update(world, 0.1);+ anim.update(world, 0.1);+ anim.update(world, 0.1);const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(10); // looped back to frame 0@@ -199,14 +196,14 @@ describe('SpriteAnimator', () => {fps: 10,loop: false,};- registerAnimClip(noLoopClip);+ anim.registerClip(noLoopClip);const entity = world.spawn();world.insert(entity, Sprite, { texture: 100 });world.insert(entity, SpriteAnimator, { clip: 'explode', loop: false });- spriteAnimatorSystemUpdate(world, 0.1); // frame 0 -> 1- spriteAnimatorSystemUpdate(world, 0.1); // frame 1 -> would be 2, clamp to 1+ anim.update(world, 0.1); // frame 0 -> 1+ anim.update(world, 0.1); // frame 1 -> would be 2, clamp to 1const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(200);@@ -220,7 +217,7 @@ describe('SpriteAnimator', () => {world.insert(entity, Sprite, { texture: 10 });world.insert(entity, SpriteAnimator, { clip: 'walk', enabled: false });- spriteAnimatorSystemUpdate(world, 0.1);+ anim.update(world, 0.1);const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(10);@@ -231,7 +228,7 @@ describe('SpriteAnimator', () => {world.insert(entity, Sprite, { texture: 10 });world.insert(entity, SpriteAnimator, { clip: 'walk', playing: false });- spriteAnimatorSystemUpdate(world, 0.1);+ anim.update(world, 0.1);const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(10);@@ -242,7 +239,7 @@ describe('SpriteAnimator', () => {world.insert(entity, Sprite, { texture: 10 });world.insert(entity, SpriteAnimator, { clip: '' });- spriteAnimatorSystemUpdate(world, 0.1);+ anim.update(world, 0.1);const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(10);@@ -253,7 +250,7 @@ describe('SpriteAnimator', () => {world.insert(entity, Sprite, { texture: 10 });world.insert(entity, SpriteAnimator, { clip: 'missing_clip' });- spriteAnimatorSystemUpdate(world, 0.1);+ anim.update(world, 0.1);const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(10);@@ -265,7 +262,7 @@ describe('SpriteAnimator', () => {world.insert(entity, SpriteAnimator, { clip: 'walk', speed: 2.0 });// speed=2, fps=10, frameDuration=0.05s- spriteAnimatorSystemUpdate(world, 0.05);+ anim.update(world, 0.05);const sprite = world.get(entity, Sprite) as SpriteData;expect(sprite.texture).toBe(20);@@ -281,7 +278,7 @@ describe('SpriteAnimator', () => {world.insert(e2, SpriteAnimator, { clip: 'walk', speed: 2.0 });// e1: frameDuration=0.1, e2: frameDuration=0.05- spriteAnimatorSystemUpdate(world, 0.05);+ anim.update(world, 0.05);const s1 = world.get(e1, Sprite) as SpriteData;const s2 = world.get(e2, Sprite) as SpriteData;