The following example assumes that:
aMovie
is an animation that can draw any frame given the current position within the animation.
aMovie
has a function that returns its duration as a TTime.
animationClock
is a TSyncableClock, allowing you to synchronize the animation to any time source.
NOTE This example uses DelayUntil to avoid time slippage. If you use DelayFor(frameRate), the time between the delays and the time that DelayFor takes are not taken into account, causing time to slip.
TTime duration = aMovie.GetDuration(); static const TSecond kBaseFrameRate = (1.0/15.0); TSeconds frameRate = kBaseFrameRate; TSeconds nextTime; TSeconds currentTime; animationClock.SetTime(TTime::kZero); nextTime = TTime::kZero; while (duration > nextTime && nextTime >= TTime::kZero) { aMovie.Draw(nextTime); nextTime += frameRate; animationClock.DelayUntil(nextTime); animationClock.Now(currentTime); if (currentTime < nextTime){ frameRate = -kBaseFrameRate; } else { frameRate = kBaseFrameRate; } }