This project is read-only.

Animations

The AnimationManager is responsible for co-ordinating, executing and terminating animations. It is a service that is provided by the IDrawingHost.
AnimationManager Members
  • AddAnimation( Animation newAnimation )
  • AddAnimation( Animation newAnimation, bool immediate )
  • ClearAllAnimations()
Internally the animations use a System.Windows.Forms.Timer component which is enabled whilst one or more animations are active and disabled once all animations have been suspended. For this reason its important not to have any continuous animations, or to disable them if the application loses focus.

Examples

Sliding an object across the screen

The following code creates an animation to move the object element from its current position to a point where its center is on the top right hand side of the screen over a period of 2 seconds.

var element = new RectangleElement() { Center= new Point( 50, 50 ), Size = new Size( 50, 50 ) };
var slidingAnimation = new PointAnimation( element, "Center", new TimeSpan( 0, 0, 2 ), new Point( hostCanvas.Width, 0 ) );
hostCanvas.AnimationManager.Add( slidingAnimation );

Sliding, rotating, scaling and changing the colour of an object

The following code expands on the previous but adds animations to rotate the element 360 degress clockwise, transition its colour to yellow and double its size.

var element = new RectangleElement() { Center= new Point( 50, 50 ), Size = new Size( 50, 50 ) };
var slidingAnimation = new PointAnimation( element, "Center", new TimeSpan( 0, 0, 2 ), new Point( hostCanvas.Width, 0 ) );
var rotatingAnimation = new FloatAnimation( element, "Angle", new TimeSpan( 0, 0, 2 ), 360.0f );
var colorAnimation = new SolidBrushAnimation( element, "Background", new TimeSpan( 0, 0, 2 ), new SolidBrush( Color.Yellow ) );
var scaleAnimation = new FloatAnimation( element, "ScaleX", new TimeSpan( 0, 0, 2 ), 2.0f );

hostCanvas.AnimationManager.Add( slidingAnimation, false );
hostCanvas.AnimationManager.Add( rotatingAnimation, false );
hostCanvas.AnimationManager.Add( colorAnimation, false );
hostCanvas.AnimationManager.Add( scaleAnimation );

Animating with Easing effects

The following code reproduces the simply animation from the first example but adds an elastic easing effect.

var element = new RectangleElement() { Center= new Point( 50, 50 ), Size = new Size( 50, 50 ) };
var slidingAnimation = new PointAnimation( element, "Center", new TimeSpan( 0, 0, 2 ), new Point( hostCanvas.Width, 0 ) );
slidingAnimation.Easing = new ElasticEasing();
hostCanvas.AnimationManager.Add( slidingAnimation );

Creating Custom Animations

To support animation over properties that are not of a currently supported type the requirement is to create a new animation class that derives from the abstract class Animation<T>. The following code demonstrates what is required for the supplied FloatAnimation.

    public class PointAnimation : Animation<Point>
    {
        public PointAnimation(object target, string propertyName, TimeSpan duration )
            : base( target, propertyName, duration )
        {
        }

        public override Point CurrentValue
        {
            get
            {
                return new Point(
                    OriginalValue.X + (int) (( FinalValue.X - OriginalValue.X ) * AdjustedPercentageComplete),
                    OriginalValue.Y + (int) (( FinalValue.Y - OriginalValue.Y ) * AdjustedPercentageComplete ));
            }
        }
    }

Last edited Sep 15, 2009 at 4:41 PM by spencen, version 4

Comments

No comments yet.