mirror of
https://github.com/motion-canvas/motion-canvas.git
synced 2026-01-11 14:57:56 -05:00
feat: time parameter for tweens
This commit is contained in:
@@ -4,16 +4,17 @@ import {Project} from '../Project';
|
||||
export function* tween(
|
||||
this: Project,
|
||||
duration: number,
|
||||
callback: (value: TimeTween) => void,
|
||||
callback: (value: TimeTween, time: number) => void,
|
||||
): Generator {
|
||||
const frames = duration * this.framesPerSeconds;
|
||||
const frames = this.secondsToFrames(duration);
|
||||
let startFrame = this.frame;
|
||||
const timeTween = new TimeTween(0);
|
||||
while (this.frame - startFrame < frames) {
|
||||
const time = this.framesToSeconds(this.frame - startFrame);
|
||||
timeTween.value = (this.frame - startFrame) / frames;
|
||||
callback(timeTween);
|
||||
callback(timeTween, time);
|
||||
yield;
|
||||
}
|
||||
timeTween.value = 1;
|
||||
callback(timeTween);
|
||||
callback(timeTween, this.framesToSeconds(frames));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user