#region File Description //----------------------------------------------------------------------------- // ScaleGameComponentAnimation.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; using Microsoft.Xna.Framework.Graphics; using System.Diagnostics; #endregion namespace CardsFramework { /// /// An animation which scales a component. /// public class ScaleGameComponentAnimation : AnimatedGameComponentAnimation { #region Fields float percent = 0; float beginFactor; float factorDelta; #endregion #region Initialzations /// /// Initializes a new instance of the class. /// /// The initial scale factor. /// The eventual scale factor. public ScaleGameComponentAnimation(float beginFactor, float endFactor) { this.beginFactor = beginFactor; factorDelta = endFactor - beginFactor; } #endregion /// /// Runs the scaling animation. /// /// Game time information. public override void Run(GameTime gameTime) { Texture2D texture; if (IsStarted()) { texture = Component.CurrentFrame; if (texture != null) { // Calculate the completion percent of animation percent += (float)(gameTime.ElapsedGameTime.TotalSeconds / Duration.TotalSeconds); // Inflate the component with an increasing delta. The eventual // delta will have the componenet scale to the specified target // scaling factor. Rectangle bounds = texture.Bounds; bounds.X = (int)Component.CurrentPosition.X; bounds.Y = (int)Component.CurrentPosition.Y; float currentFactor = beginFactor + factorDelta * percent - 1; bounds.Inflate((int)(bounds.Width * currentFactor), (int)(bounds.Height * currentFactor)); Component.CurrentDestination = bounds; } } } } }