#region File Description
//-----------------------------------------------------------------------------
// TransitionGameComponentAnimation.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
#endregion
namespace CardsFramework
{
///
/// An animation which moves a component from one point to the other.
///
public class TransitionGameComponentAnimation : AnimatedGameComponentAnimation
{
#region Fields
Vector2 sourcePosition;
Vector2 positionDelta;
float percent = 0;
Vector2 destinationPosition;
#endregion
#region Initializations
///
/// Initializes a new instance of the class.
///
/// The source position.
/// The destination position.
public TransitionGameComponentAnimation(Vector2 sourcePosition,
Vector2 destinationPosition)
{
this.destinationPosition = destinationPosition;
this.sourcePosition = sourcePosition;
positionDelta = destinationPosition - sourcePosition;
}
#endregion
///
/// Runs the transition animation.
///
/// Game time information.
public override void Run(GameTime gameTime)
{
if (IsStarted())
{
// Calculate the animation's completion percentage.
percent += (float)(gameTime.ElapsedGameTime.TotalSeconds /
Duration.TotalSeconds);
// Move the component towards the destination as the animation
// progresses
Component.CurrentPosition = sourcePosition + positionDelta * percent;
if (IsDone())
{
Component.CurrentPosition = destinationPosition;
}
}
}
}
}