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
feat: support per-frame duration in sprite animation clips
esengine59836e8ce7de
diff --git a/editor/src/panels/inspector/AnimClipInspector.ts b/editor/src/panels/inspector/AnimClipInspector.tsindex e07fb862f..20af19903 100644--- a/editor/src/panels/inspector/AnimClipInspector.ts+++ b/editor/src/panels/inspector/AnimClipInspector.ts@@ -10,7 +10,7 @@ interface AnimClipAssetData {type: 'animation-clip';fps?: number;loop?: boolean;- frames: { texture: string }[];+ frames: { texture: string; duration?: number }[];}const MIN_FPS = 1;@@ -20,6 +20,7 @@ interface FrameInfo {texture: string;displayPath: string;thumbnailUrl: string | null;+ duration?: number;}function resolveTexturePath(ref: string): string {@@ -49,6 +50,7 @@ export async function renderAnimClipInspector(container: HTMLElement, path: stritexture: f.texture,displayPath: resolveTexturePath(f.texture),thumbnailUrl: null,+ duration: f.duration,}));const state = {@@ -159,6 +161,8 @@ function renderFrameList(frames: FrameInfo[]): string {}</div><span class="es-animclip-frame-name" title="${frame.displayPath}">${getFileName(frame.displayPath)}</span>+ <input type="number" class="es-animclip-frame-duration" data-index="${i}" min="0" step="0.01"+ placeholder="auto" value="${frame.duration ?? ''}" title="Duration (seconds). Leave empty to use global FPS."><button class="es-btn es-btn-icon es-animclip-delete-btn" data-index="${i}" title="Remove frame">${icons.x(12)}</button>@@ -186,6 +190,17 @@ function setupDeleteButtons(loadThumbnails(section, state, filePath);});});++ const durationInputs = section.querySelectorAll('.es-animclip-frame-duration');+ durationInputs.forEach(input => {+ input.addEventListener('change', async () => {+ const el = input as HTMLInputElement;+ const index = parseInt(el.dataset.index!, 10);+ const val = el.value.trim();+ state.frames[index].duration = val ? parseFloat(val) || undefined : undefined;+ await save(state, filePath);+ });+ });}function setupDropZone(@@ -287,7 +302,11 @@ async function save(type: 'animation-clip',fps: state.fps,loop: state.loop,- frames: state.frames.map(f => ({ texture: f.texture })),+ frames: state.frames.map(f => {+ const entry: { texture: string; duration?: number } = { texture: f.texture };+ if (f.duration !== undefined) entry.duration = f.duration;+ return entry;+ }),};const platform = getPlatformAdapter();diff --git a/sdk/src/animation/AnimClipLoader.ts b/sdk/src/animation/AnimClipLoader.tsindex e4b772c84..b7bb7c5ac 100644--- a/sdk/src/animation/AnimClipLoader.ts+++ b/sdk/src/animation/AnimClipLoader.ts@@ -11,6 +11,7 @@ import type { SpriteAnimClip, SpriteAnimFrame } from './SpriteAnimator';export interface AnimClipFrameData {texture: string;+ duration?: number;atlasFrame?: {x: number;y: number;@@ -57,6 +58,7 @@ export function parseAnimClipData(frames: data.frames.map(f => {const frame: SpriteAnimFrame = {texture: textureHandles.get(f.texture) ?? 0,+ duration: f.duration,};if (f.atlasFrame) {const af = f.atlasFrame;diff --git a/sdk/src/animation/SpriteAnimator.ts b/sdk/src/animation/SpriteAnimator.tsindex 0226828b3..fefc8b7fc 100644--- a/sdk/src/animation/SpriteAnimator.ts+++ b/sdk/src/animation/SpriteAnimator.ts@@ -86,7 +86,8 @@ export function spriteAnimatorSystemUpdate(world: World, deltaTime: number): voiconst clip = clipRegistry.get(animator.clip);if (!clip || clip.frames.length === 0) continue;- const frameDuration = 1.0 / (clip.fps * animator.speed);+ const currentFrame = clip.frames[animator.currentFrame];+ const frameDuration = currentFrame?.duration ?? 1.0 / (clip.fps * animator.speed);const needsInitialApply = animator.frameTimer === 0 && animator.currentFrame === 0;