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:

<UserControl 
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
   xmlns:Execution="clr-namespace:Balder.Core.Execution;assembly=Balder.Core" 
   xmlns:Geometries="clr-namespace:Balder.Core.Lighting;assembly=Balder.Core" 
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   xmlns:local="clr-namespace:MyGame"
   x:Class="MyGame.MainPage">
   <UserControl.Resources>
      <Storyboard x:Name="_cameraStoryboard">
         <DoubleAnimationUsingKeyFrames Storyboard.TargetName="_game" 
                                        Storyboard.TargetProperty="(Game.Camera).(Camera.Target).(Vector.Y)" 
                                        AutoReverse="True" 
                                        RepeatBehavior="Forever">
            <EasingDoubleKeyFrame KeyTime="00:00:00" Value="5" >
               <EasingDoubleKeyFrame.EasingFunction>
                  <CircleEase EasingMode="EaseOut"/>
               </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
            <EasingDoubleKeyFrame KeyTime="00:00:02" Value="0" >
               <EasingDoubleKeyFrame.EasingFunction>
                  <CircleEase EasingMode="EaseIn"/>
               </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
         </DoubleAnimationUsingKeyFrames>
      </Storyboard>
   </UserControl.Resources> 

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

In your code-behind you start the storyboard:
_cameraStoryboard.Begin();


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 9:06 PM by adept, version 7

Comments

No comments yet.