This is a mirror of official site: http://jasper-net.blogspot.com/

MMORPG programming in Silverlight Tutorial: Animate the object

| Tuesday, March 2, 2010
Now, there are so many articles to introduce how to create animation in XAML by Blend, so I don’t plan to say more on this topic. It make many people puzzled “Silverlight is just Microsoft’s Flash, no difference”. If you follow this style, it will make no sense.
   We must do something to show all the potential of the Silverlight in game domain. So in my tutorial, I will use C# rather than XAML as possible as I can. It is more flexible in game architecture than Flash; at last, all the tutorials will make up a game engineer, which is my purpose that I want to achieve.


   Let’s return to the topic of this article, “How to create animation on object?”


   In Silverlight, there are 3 methods to create animation.


   1) Storyboard
   This method is recommended by Microsoft, so I introduce it at first.
   Now I will do a demo to show how to use Storyboard in C#.

   1st, create a Silverlight project, open the MainPage.xaml, modify the xaml file as follows:

<UserControl x:Class="SilverlightTutorialApplication.MainPage"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   >
   <Canvas x:Name="Carrier" Width="800" Height="600" Background="Silver" MouseLeftButtonDown="Carrier_MouseLeftButtonDown" />
</UserControl>

   In this snippet code, I create a canvas named Carrier, and set its dimension to 800 * 600. I set its background to Silver, donot remove the background color, otherwise, if there is nothing in the canvas, it’s MouseLeftButtonDown event won’t be hired.

   Why I use Canvas as my container? Because canvas can do absolute positioning, it is convenient to handle object’s moving on it.

Read more: Jianqiang's Silverlight Blog Part 1, Part 2

Posted via email from jasper22's posterous

0 comments: