From 19995cf23303fee4418554fcb96785d2cfd8de87 Mon Sep 17 00:00:00 2001 From: spacex_2020 <540240126@qq.com> Date: Sat, 22 Apr 2023 23:22:32 +0800 Subject: [PATCH] feat: Added animation seek method to display graphics at a certain point in time --- src/animation/Animation.ts | 14 ++++++++++++++ src/animation/Clip.ts | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/animation/Animation.ts b/src/animation/Animation.ts index cf2ec8569..b901bceda 100644 --- a/src/animation/Animation.ts +++ b/src/animation/Animation.ts @@ -194,6 +194,20 @@ export default class Animation extends Eventful { this._startLoop(); } + seek(timestamp: number) { + this._time = getTime() - timestamp; + let clip = this._head; + while(clip) { + clip.loop = true; + clip.setStartTime(this._time + clip.getDelay()); + clip = clip.next; + } + this._pausedTime = 0; + this._pauseStart = getTime(); + this._paused = true; + this.update(); + } + /** * Stop animation. */ diff --git a/src/animation/Clip.ts b/src/animation/Clip.ts index 0acf6bf40..b71d3a719 100644 --- a/src/animation/Clip.ts +++ b/src/animation/Clip.ts @@ -75,6 +75,14 @@ export default class Clip { opts.easing && this.setEasing(opts.easing); } + getDelay() { + return this._delay; + } + + setStartTime(startTime: number) { + this._startTime = startTime; + } + step(globalTime: number, deltaTime: number): boolean { // Set startTime on first step, or _startTime may has milleseconds different between clips // PENDING