feat: time parameter for tweens

This commit is contained in:
aarthificial
2022-03-19 15:13:27 +01:00
parent 24db5613ac
commit 3fe90edc49

View File

@@ -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));
}