The Animating XAML Clip Art posting shows you how to creating a bouncing effect (without the flattening.) In this posting, we'll explore how to create that flattening effect in a bounce, which is simply a set of animations that change the width and height of the object at the point of impact. At the bottom of this posting you can find an attached XAML file (RedBouncingBall.xaml).
The X value is animated by a type DoubleAnimation. The animation simply moves the ball along the x-axis at a constant rate:
<!--
The Y value is animated by a type DoubleAnimationUsingKeyFrames, and uses SplineDoubleKeyFrame objects to create a variable rate of change in the ball's up and down motion. This results in the ball having a more realistic bounce by accelerating and decelerating the motion. For more info on SplineDoubleKeyFrame, see the Animating XAML Clip Art posting.
The ScaleX value is animated by a type DoubleAnimationUsingKeyFrames, which uses a set of four LinearDoubleKeyFrame objects. The KeyTime property of the LinearDoubleKeyFrame objects is synchronized with the preceding animation so that the change to the width of the ball occurs when the ball is at its lowest point.
Notice that the flattening effect does not start until the KeyTime value is at 2 seconds, which is just before it reaches the point of impact. In addition, the ball is restored to its original width at 2.5 seconds. This means the flattening effect occurs briefly at the lowest point of the ball's bounce. Changing the Value property to 1.3 has the effect of slightly increasing the width of the ball:
The ScaleY value is animated by a type DoubleAnimationUsingKeyFrames, which also uses a set of four LinearDoubleKeyFrame objects. The KeyTime property of the LinearDoubleKeyFrame objects is synchronized with the preceding animation so that the change to the height of the ball occurs when the ball is at its lowest point. Changing the Value property to 0.7 has the effect of slightly decreasing the height of the ball:
<
Now when the animations run, they all run at a relatively slower rate. In this case, the animations run at half the normal speed.
Enjoy,Lorin