Getting physical Windows 8 Modern UI XAML with the Physics Helper XAML
- Posted: Sep 03, 2012 at 6:00AM
- 8,823 views
- 2 comments
Loading user information from Channel 9
Something went wrong getting user information from Channel 9
Loading user information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Today's Mobile/Modern UI Monday project from Andy Beaulieu is in an area that I just can't get enough of, Physics in our app's. This project not only brings us a Physics Helper, but one for XAML and works in three of the major XAML platforms, Windows 8/Modern UI, Windows Phone and Silverlight
Today I released version 1.1 of Physics Helper XAML, which allows you to easily create 2D Physics Games and Simulations for the following platforms:
- Windows 8
- Windows Phone 7
- Silverlight 5
XAML has great support for 2D graphics including hardware acceleration, making it an excellent candidate for 2D physics based games. And because of XAML's extensive form controls and powerful project templates, it makes it super easy to create your games menus and input UI. Also, it is possible to target the three platforms using a single set of XAML assets for graphics and logic.
I personally used the Physics Helper XAML project as the core for my first (and award winning) Windows 8 game, Physamajig. To get started yourself, I recommend:
Physics Helper XAML allows you to easily create 2D physics based games and simulations for Windows 8, Windows Phone 7 and Silverlight 5 using C# or VB. It is a port of the Physics Helper and uses the Farseer Physics Engine.
Why a Separate Version?
When I began porting the Physics Helper project to Windows 8, I realized that there were many breaking changes in WinRT and missing functionality such as Behaviors. It was much simpler to create a new version for Metro/WinRT and then port that new version to Windows Phone and other platforms. I think that the end result is much simpler and cleaner, as an added bonus!
For more details and how to get started, see the Documentation page.
Here's a snap of the Windows 8 Solution;
And of it running (which compiled and ran for me the very first time, which is always nice...
This is one of those projects that you really need to play with or see in a video. Static pictures just doesn't do it justice.
As you saw mentioned above, there's a nice getting started guide too;
Sample ProjectsOnce you have a development environment and hardware setup, you can download the source codeand check out the sample projects inside the VS11 solution.
Demo.SimpleSet Demo.Simple as your startup project and run the solution. This shows a no-code scenario with a ragdoll and stack of blocks. Here are the main parts of the simple demo:
- ucBlock.xaml defines the Block sprite.
- ucRagDoll.xaml defines a rag doll with appendages and joints bringing them together.
- MainPage.xaml creates instances of ucBlock and ucRagDoll. There is one line of code in MainPage.xaml.cs which calls ScaleToObject. This allows the game canvas to scale to full screen.
Demo.AdvancedSet Demo.Advanced as your startup project and run the solution. This shows how to dynamically add and delete user controls, track performance, and use nested Storyboard animations inside physics objects. Here are the main highlights of the advanced demo:
- the code-beind file MainPage.xaml.cs shows how to handle the TimerLoop and Collision events raised by the PhysicsCanvas.
- The AddAnItem method shows how to dynamically add a complex UserControl containing multiple sprites and joints.
Using Visual Studio
Let's walk through creating a simple physics simulation using XAML inside Visual Studio.
With this helper, your just a little code away from having physics in your next Windows 8 Modern UI app...