One of the nice things in Silverlight is the ability to declaratively set up animations through what is known as Storyboards.
A storyboard can contain one or more animations on a timeline. You can either use simple animations with a source value and a destination value and a given timeframe it should animate over, or you can create more advanced animations with keyframes. All properties on the controls in Balder can be animated.

Example of animating the camera on your game:

      <Storyboard x:Name="_cameraStoryboard">
         <DoubleAnimationUsingKeyFrames Storyboard.TargetName="_game" 
            <EasingDoubleKeyFrame KeyTime="00:00:00" Value="5" >
                  <CircleEase EasingMode="EaseOut"/>
            <EasingDoubleKeyFrame KeyTime="00:00:02" Value="0" >
                  <CircleEase EasingMode="EaseIn"/>

   <Grid x:Name="LayoutRoot">
      <Execution:Game x:Name="_game" Width="800" Height="600" DebugLevel="BoundingSpheres">
         <Geometries:Mesh x:Name="_teapot"  AssetName="teapot.ASE"/>

In your code-behind you start the storyboard:

As you may notice, the TargetProperty on the DoubleAnimationUsingKeyFrames might seem a bit funky, all it is referring to is the DependencyProperty it will work with on each object.
The TargetName defines the first object, the target, we then in TargetProperty say (Game.Camera), which is the DependencyProperty called Camera that is defined on the Game control. Then we say (Camera.Target), which is the Target DependencyProperty defined on the CameraControl and finally we say (Vector.Y), which then refers to the Y DependencyProperty on the Vector class.

For more details on how DependencyProperties come together in animations, please read this.

Last edited Dec 15, 2009 at 8:06 PM by adept, version 7


No comments yet.