Play the animation with the juggler
.
If the optional gotoFrame
argument is specified, the animation will
start at the given frame number, otherwise the animation will start at
the current frame.
If the optional stopFrame
argument is specified, the animation will
stop at the given frame number, otherwise the animation will continue
to run depending on the loop configuration.
The returned future is completed on the first occurrence of:
- the animation does not loop and the last frame was reached.
- the optionally specified argument
stopFrame
was reached. - the stop method was called.
Source
Future playWith(Juggler juggler, {int gotoFrame, int stopFrame}) { _play = true; _frameTime = null; _currentFrame = gotoFrame ?? currentFrame; var completed = this.onComplete.first; var currentTime = juggler.elapsedTime; var subscription = juggler.onElapsedTimeChange.listen((elapsedTime) { advanceTime(elapsedTime - currentTime); currentTime = elapsedTime; if (currentFrame == stopFrame) this.stop(); }); completed.then((_) => subscription.cancel()); return completed; }