Last active
August 9, 2019 19:48
-
-
Save pigeonfresh/6f9ce0a52a120ab7619fa335c273909b to your computer and use it in GitHub Desktop.
A small class to be able to lerp a Greensock Timeline and handle it's progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TimelineMax, TimelineLite, TweenMax } from 'gsap'; | |
export default class LerpedTimeline { | |
public progress: number = 0; | |
public readonly timeline: TimelineMax | TimelineLite; | |
private readonly ease: number; | |
private currentProgress: number = 0; | |
constructor(timeline, ease: number = 0.1) { | |
this.timeline = timeline; | |
this.ease = ease; | |
TweenMax.ticker.addEventListener('tick', this.handleTick); | |
} | |
private handleTick = (): void => { | |
this.currentProgress = this.currentProgress + (this.progress - this.currentProgress) * this.ease; | |
this.timeline.progress(this.currentProgress); | |
}; | |
public dispose() { | |
TweenMax.ticker.removeEventListener('tick', this.handleTick); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment