This section explains how to cycle (loop) an existing animation.

Creating a Cyclic Animation

Most animations, such a FromToByAnimation<(Of <(<'T>)>)> or KeyFrameAnimation<(Of <(<'T>)>)>, do not automatically support cycling (looping). If these types of animations should be looped, an AnimationClip<(Of <(<'T>)>)> needs to be used:

C# Copy imageCopy
// Create a simple color animation.
ColorKeyFrameAnimation animation = new ColorKeyFrameAnimation
colorAnimation.KeyFrames.Add(new KeyFrame<Color>(TimeSpan.FromSeconds(0), Color.Red));
colorAnimation.KeyFrames.Add(new KeyFrame<Color>(TimeSpan.FromSeconds(1), Color.Green));
colorAnimation.KeyFrames.Add(new KeyFrame<Color>(TimeSpan.FromSeconds(3), Color.Blue));
colorAnimation.KeyFrames.Add(new KeyFrame<Color>(TimeSpan.FromSeconds(4), Color.Red));

// Use an AnimationClip<T> to turn the 4 second colorAnimation into 
// an animation that loops forever.
_cyclicAnimation = new AnimationClip<Color>(animation)
{
  LoopBehavior = LoopBehavior.Cycle,
  Duration = TimeSpan.MaxValue,
};

Note that the first key frame and the last key frame ("loop key") should have the identical values in order to achieve smooth transitions between cycles.

An AnimationClip<(Of <(<'T>)>)> can be used to cycle animations that implement IAnimation<(Of <(<'T>)>)>. A TimelineClip is a more general variant that can be used to cycle anything that implements ITimeline.

See Also

Other Resources