From 79140cd7f24d2bdc2108463abcb03806c2f2d6cd Mon Sep 17 00:00:00 2001 From: Hanxing Yang Date: Fri, 28 Jun 2024 15:19:50 +0800 Subject: [PATCH] update model animation (#620) --- spx-gui/src/models/animation.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/spx-gui/src/models/animation.ts b/spx-gui/src/models/animation.ts index 13a103d03..a0e2bfc34 100644 --- a/spx-gui/src/models/animation.ts +++ b/spx-gui/src/models/animation.ts @@ -27,7 +27,6 @@ const defaultFps = 25 // TODO export type AnimationInits = { duration?: number - anitype?: number onStart?: ActionConfig // not supported by builder: @@ -37,6 +36,7 @@ export type AnimationInits = { } export type RawAnimationConfig = AnimationInits & { + anitype?: number from?: number | string to?: number | string } @@ -80,11 +80,24 @@ export class Animation { costume.setParent(this) } this.costumes = costumes - if (this.duration == null) { + if (this.duration === 0) { this.duration = costumes.length / defaultFps } } + /** + * Ungroup costumes, which will be added back to sprite. + * Typically called before the animation removed from the sprite. + */ + ungroup() { + if (this.sprite == null) throw new Error('sprite expected') + const costumes = this.costumes + this.setCostumes([]) + for (const costume of costumes) { + this.sprite.addCostume(costume) + } + } + duration: number setDuration(duration: number) { this.duration = duration @@ -112,7 +125,7 @@ export class Animation { * Create instance with default inits * Note that the "default" means default behavior for builder, not the default behavior of spx */ - static async create( + static create( nameBase: string, sprite: Sprite, costumes: Costume[],