Free 30 days to Launch!
(not a paid advertisement)
30 Day to Launch Phone
Mobile games can be a challenge. Developing games that can take can operate on many platforms is even more difficult.
That is, unless you are using Silverlight and Expression 4!
WOW! Oh, wait a minute, does Silverlight work with the “current’ Internet Mobile Browser (the one in the Win Phone Emulator), I have been told: No.
So, how does Silverlight work in the current Win Phone Emulator? Ummmm? As an out of browser experience.
Out of browser? Wow, is that like out of body? Sort of.
But no matter lets have some fun with Silverlight on the Mobile devices. (Click images to enlarge.)
Add a new item and then select the
Do this by right clicking on the Solution (in this case Geometry, but might be different for your project/solution)
Once you are done, click Add and then a xaml and class will be built.
This is the User Control type of xaml.
First of all you will see that there are two files:
Usually it is a good practice to change the names to reflect your project, especially usually you will be living with the name for a long time.
This is what your MainPage.xaml will look like when you start Visual Studio 2010 Express for Windows Phone
There are variations if you are using one of the other Visual Studio 2010 versions.
<--- Paste this code into triangle.xaml --->
<UserControl x:Class="Geometry.Triangle" 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" mc:Ignorable="d" d:DesignHeight="26" d:DesignWidth="40"> <Canvas x:Name="LayoutRoot" RenderTransformOrigin="0.5,0.5"> <Canvas.RenderTransform> <RotateTransform x:Name="rotateTransform" Angle="0"/> </Canvas.RenderTransform> <Path Data="M0,38 L14, 0, 50, 100z" Stroke="Black" StrokeThickness="4"/> </Canvas>
</UserControl>
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes;
namespace Geometry { public partial class Triangle : UserControl { public Triangle() { InitializeComponent(); }
public double RotationAngle { get { return rotateTransform.Angle; } set { rotateTransform.Angle = value; } }
} }
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls;
namespace Geometry { public partial class MainPage : PhoneApplicationPage { Storyboard loopGame;
public MainPage() { InitializeComponent();
loopGame = new Storyboard();
loopGame.SetValue(FrameworkElement.NameProperty, "loopgame");
this.Resources.Add("loopgame", loopGame);
loopGame.Completed += new EventHandler(loopGame_Completed);
loopGame.Begin();
SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
}
void loopGame_Completed(object sender, EventArgs e) { Update();
loopGame.Begin(); }
void Update() { Triangle.RotationAngle = Triangle.RotationAngle + 15;
} } }
<phoneNavigation:PhoneApplicationPage x:Class="Geometry.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phoneNavigation="clr- namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Navigation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:geometry ="clr-namespace:Geometry" mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}"> <Grid x:Name="LayoutRoot" Background="Honeydew"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <!--TitleGrid is the name of the application and page title--> <Grid x:Name="TitleGrid" Grid.Row="0"> <TextBlock Text="Big Phat Triangle" x:Name="textBlockPageTitle" Style="{StaticResource PhoneTextPageTitle1Style}"/> <TextBlock Text="Rotating Triangle" x:Name="textBlockListTitle" Style="{StaticResource PhoneTextPageTitle2Style}"/> </Grid> <!--ContentGrid is empty. Place new content here--> <Grid x:Name="ContentGrid" Grid.Row="1"> <Canvas x:Name="gameSurface"> <geometry:Triangle x:Name="Triangle" Canvas.Left="200" Canvas.Top="220"/> </Canvas> </Grid> </Grid> </phoneNavigation:PhoneApplicationPage>
What did we learn here?
I will use this example over the next few blog entries so if you put it together, make sure to keep it!
What’s next? Review of the code.