Click or drag to resize
DigitalRuneHow To: Immediately Apply an Animation Value

This topic explains how to immediately apply a new animation value when an animation is started.

Immediately applying an animation value

When a new animation is started the animated properties do not change immediately. Animation values are only updated and applied when the methods AnimationManagerUpdate(TimeSpan) and AnimationManagerApplyAnimations are called, which happens usually at some point in the game loop.

But in certain cases the animated properties should change immediately. In these cases the method UpdateAndApplyAnimation (or one of its overloads in the IAnimationService) or UpdateAndApply of the AnimationController can be called. These methods instantly evaluate all animations that affect the specified objects or properties and apply the new animation values.

C#
var animationController = animationService.StartAnimation(animation, property);

// The value of 'property' has not changed yet, because
// AnimationManager.Update() and AnimationManager.ApplyAnimations()
// has not been called. Other components that read the value of
// 'property' will see the original value.
// But we can force the animation system to evaluate the animation
// and apply the animation value right away:
animationController.UpdateAndApply();