Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

Silverlight Tip of the Day #107 – Animation Easing Demo

Animation Easing allows for you to apply built in animation functions to your Silverlight controls. The result is a variety of animation effects that make your controls move in a more realistic way. For example, you can add springiness to your controls, set how many times you want it to bounce when it hits a destination point, etc. The functions that you can set include:

  • BackEase – Moves the ball backwards by an amount specified through its amplitude before moving forward.
  • BounceEase – Created an effect like a bouncing ball.
  • CircleEase – Accelerates the animation based upon a circular function.
  • CubicEase  - Accelerates the animation based upon a cubic function.
  • ElasticEase – Uses springiness and oscillation to animate.
  • ExponentialEase – Accelerates the animation based upon an exponent value.
  • PowerEase – Accelerates the animation based upon a power of time.
  • QuadraticEase – Accelerates the animation based upon the square of time.
  • QuarticEase – Accelerates the animation based upon the cube of time.
  • QuinticEase – Accelerates the animation based upon the time to the power of 5.
  • SineEase – Accelerates the animation along a sine wave.

Each of these has can have an EasingMode set to one of the following options:

  1. EaseOut – Ease takes place at the beginning of the animation.
  2. EaseIn – Ease takes place at the end of the animation.
  3. EaseInOut – EaseIn takes place for half the animation followed by EaseOut.

In addition, you can set the Duration, From and To values for the animation.

The best way to see what each of these do is to simply to try them out via this demo. Try modifying any properties that are specifically unique to the animation.

The animation functions listed above are applied directly to a storyboard that is then used to target and animate a given control. The XAML I use for each ball is as follows:

<UserControl x:Class="BouncingBall.Ball"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Canvas>
        <Canvas.Resources>
            <Storyboard x:Name="BallSB">
                <DoubleAnimation x:Name="BallDA" Completed="DoubleAnimation_Completed" From="0" To="1000" Duration="0:0:05"
                             Storyboard.TargetName="TargetBall" Storyboard.TargetProperty="(Canvas.Top)">
                    <DoubleAnimation.EasingFunction>                        
                        <BounceEase x:Name="Easing" Bounces="10" EasingMode="EaseOut" Bounciness="2"></BounceEase>
                    </DoubleAnimation.EasingFunction>
                </DoubleAnimation>
            </Storyboard>
        </Canvas.Resources>
        <Image x:Name="TargetBall" Source="ball.png" ImageOpened="Image_ImageOpened"></Image>
    </Canvas>
</UserControl>

Thanks,
--Mike

Comments

DZaK said:

Hi,

How to run your demo? ;)

--

Jacek Ciereszko

# April 17, 2009 2:50 AM

mike.snow said:

Make certain you have Silverlight 3 Beta 1 installed to see the demo. Let me know if you still can't see/run it.

# April 17, 2009 5:00 PM

JasonWei said:

oh yeah..

silverlight 3 beta 1.

so ...

could u let it run silverlight 2?

i thinks almost silverlight 2 for everyone..

# April 21, 2009 4:50 AM

mike.snow said:

This is a Silverlight 3 feature :) Wouldn't run in SL 2.

# April 21, 2009 9:57 AM

misschoudhary said:

I am not able to download silverlight 3 beta could youplase tell me the link frm where to get it.. Sorry for the trouble.

# April 27, 2009 2:22 AM

mike.snow said:

SL3 can be installed from here:

silverlight.net/.../default.aspx

The link is in the box on the right side. Thanks.

# April 27, 2009 11:30 AM

misschoudhary said:

Thanks Mike I will download them and try the example given by you

# April 28, 2009 9:03 AM

misschoudhary said:

I m not able to install the toolkit it is given fatal error???????

# April 29, 2009 1:21 AM

mike.snow said:

What link did you install from?

Try uinstalling all Silverlight components first then try the install.

# April 29, 2009 2:07 PM

ADHDeveloper said:

Your book keeps getting delayed on amazon.ca :(

# May 26, 2009 12:36 PM

mike.snow said:

Interesting, what was the original due date? All I know is it should be out in June. Thanks!

# May 26, 2009 12:40 PM

ADHDeveloper said:

Initially I think it was going to be mid June, but then got delayed to june 26th and now early july.

# May 26, 2009 2:05 PM

ADHDeveloper said:

Ah wait nevermind, the ship date is now 26th of June, I think it has slipped a few days since I last noticed. When I originally preordered it was somewhere in Mid June.

Really looking forward to it :)

# May 26, 2009 2:06 PM

LenR said:

I just got a note from Amazon saying they will cancel my preorder today if I don't say I want them to keep trying. As it is shipping today I wonder how many others will get canceled. I told them to keep trying, the book looks interesting. I also bookmarked the site.

Thanks for the good stuff.

LenR

# June 30, 2009 4:57 PM

NewsPeeps said:

Thank you for submitting this cool story - Trackback from NewsPeeps

# August 8, 2009 6:36 PM

kongkoro said:

This demo is not displaying for me, and I have

Silverlight v.3.0.40723.0

cool article tho!

# August 11, 2009 11:28 AM