advance method
Advances playbackTime by deltaTime seconds (scaled by
playbackTimeScale).
No-op when the clip is not playing or deltaTime <= 0. Handles
looping behavior: if loop is false, playback clamps and pauses
at the boundaries; if true, it wraps around.
Implementation
void advance(double deltaTime) {
if (!playing || deltaTime <= 0) {
return;
}
deltaTime *= playbackTimeScale;
_playbackTime += deltaTime;
// Handle looping behavior.
if (_animation.endTime == 0) {
_playbackTime = 0;
return;
}
if (!loop && (_playbackTime < 0 || _playbackTime > _animation.endTime)) {
// If looping is disabled, clamp to the end (or beginning, if playing in
// reverse) and pause.
pause();
_playbackTime = clampDouble(_playbackTime, 0, _animation.endTime);
} else if ( /* loop && */ _playbackTime > _animation.endTime) {
// If looping is enabled and we ran off the end, loop to the beginning.
_playbackTime = _playbackTime.abs() % _animation.endTime;
} else if ( /* loop && */ _playbackTime < 0) {
// If looping is enabled and we ran off the beginning, loop to the end.
_playbackTime =
_animation.endTime - (_playbackTime.abs() % _animation.endTime);
}
}