//----------------------------------------------------------------------------- // RotationGameComponentAnimation.cs // // Animation which rotates a component over time //----------------------------------------------------------------------------- using System; using Microsoft.Xna.Framework; namespace CardsFramework { /// /// An animation which rotates a component from one angle to another. /// public class RotationGameComponentAnimation : AnimatedGameComponentAnimation { private float percent = 0; private float beginRotation; private float rotationDelta; /// /// Initializes a new instance of the class. /// /// The initial rotation angle in radians. /// The eventual rotation angle in radians. public RotationGameComponentAnimation(float beginRotation, float endRotation) { this.beginRotation = beginRotation; rotationDelta = endRotation - beginRotation; } /// /// Runs the rotation animation. /// /// Game time information. public override void Run(GameTime gameTime) { if (IsStarted()) { // Calculate the completion percent of animation percent += (float)(gameTime.ElapsedGameTime.TotalSeconds / Duration.TotalSeconds); percent = MathHelper.Clamp(percent, 0f, 1f); // Smoothly interpolate rotation Component.CurrentRotation = beginRotation + rotationDelta * percent; } } } }