SpriteHand
Module Border
  Physics Games in Silverlight on Windows Phone 7
Module Border
Location: BlogsAndy's Blog    
Posted by: host 3/17/2010 9:11 PM


The
Physics Helper Library now supports Windows Phone Development!

[DOWNLOAD PHYSICS HELPER]

[SEE A TEASER]

[DOWNLOAD SAMPLE PHONE PROJECT]

* UPDATE 05/17/10: Fixed for April Refresh of WP7 Tools



If you want to create some fun physics-based games for this upcoming platform, you’ll first want to first visit the Windows Phone Development site and download the tools you’ll need.

The Physics Helper Library is a collection of Behaviors and UserControls that make is easier to create 2D physics games in Silverlight using the Farseer Physics Engine. The Physics Helpers have gone through several different iterations – in their original release for Silverlight 2, they were solely UserControls; in Silverlight 3 support for Behaviors was added, and later WPF support was added into the library, thanks to contributions from the community.

Now that everyone, including myself, is hyped about Silverlight on the Windows Phone, I was eager to get the library working under the new emulator, and it turns out that it didn’t take much effort at all because of the great job the Silverlight team did to make Windows Phone a “real” Silverlight (version 3) implementation!

Because Windows Phone contains a true Silverlight 3 implementation, assemblies are binary compatible, and you don’t even need to recompile the Physics Helper assemblies for the Phone. In fact, all I needed to do was remove a reference to System.Windows.Browser (as that is missing on the phone), and I was up and running.

Another Physics Sample!

Pete Blois (on the Microsoft Blend team), has also ported his Box2D Engine based samples to the Windows Phone and created a really neat physics based game which he demoed at MIX10. If you want to check out the Box2D engine instead of Farseer, you can check out Pete’s work.

Accelerometer Support

The Windows Phone doesn’t have any useful hardware buttons for games, so you can bet that the Accelerometer on the device will be very important for input. Mike Harsh gave a great presentation at MIX where he explained the axes of the Accelerometer:

As the device is tilted, you’ll usually get a value between -1 and 1 for each axis. I say usually because if you fling the device around you could actually get a bigger number – that’s because the value is based on G-force. At least, that is the idea, I haven’t had  my hands on an actual device to confirm J

The problem is that the emulator included with the Windows Phone developer tools does NOT simulate an accelerometer. But in chatting with Pete Blois, a good workaround for now is to use a mouse drag event to emulate the accelerometer “tilt.” You can see this method in the Sample project at the top of this blog post. Note that there is an “AccelerometerWrapper” class which handles the Perspective Transform and mimicking the Accelerometer with mouse movements. Again, I haven’t tested this on an actual device but from what I’ve heard this is a good simulation of the accelerometer data.

The Sample Project

Let’s dissect the sample a bit. Because of the similarities in code between browser-based Silverlight 3 and Phone-based Silverlight 3, I am taking the approach of a single solution that contains both a SL3 project AND a Windows Phone project. Then I am using a linked file to reuse the exact same code for the main game user control (ucMainGame):

I think I will stick to this approach because it will allow supporting multiple platforms (web + phone) with a single project. And to be honest I’m not all that happy with the Windows Phone Emulator’s speed so for most debugging tasks I can stick with the Silverlight 3 web project.

More Resources

If you’re new to the Physics Helper, check out the videos and info at http://physicshelper.codeplex.com.

If you’re new to Windows Phone Development (like all of us), you’ll be happy to know that 90% of the game is knowing Silverlight. But for the other 10%, check out these sessions from MIX:

Changing our Game – an Introduction to Windows Phone 7 Series

Authoring for Windows Phone, Silverlight 4 and WPF 4 with Expression Blend

Overview of the Windows Phone 7 Series Application Platform

Building Windows Phone Applications with Silverlight, Part 1

Building Windows Phone Applications with Silverlight, Part 2

Silverlight Performance on Windows Phone

 

Permalink |  Trackback

Comments (12)   Add Comment
Игры с физикой на Silverlight в Windows Phone 7    By TrackBack on 3/18/2010 12:36 PM
Thank you for submitting this cool story - Trackback from progg.ru
# progg.ru

Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 3/20/2010 11:22 PM
I love you work with the physics engine, can you adress sound on phone 7 (like explosions)

Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 3/29/2010 8:16 AM
For sound on WP7, you should use the XNA library SoundEffect classes. If you download the latest PhysicsHelper, take a look at the SoundMain class, which wraps the XNA sound api.

Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 4/12/2010 8:18 AM
Hey, physics games is one of the interesting in the world, but if don`t understand physics problem , if you you will know that, game will be more interesting and easy. Good luck



Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 5/17/2010 12:40 PM
Hi Andy! great work once again!
I'm having an error compiling with the latest developer tools:
Error 1 'Microsoft.Devices.Sensors.AccelerometerSensor' does not contain a definition for 'Default' AccelerometerPhysics\AccelerometerWrapper.cs 44 47 AccelerometerPhysics.Phone

Do you have an update ?
bye
Tiago Andrade e Silva

Re: Physics Games in Silverlight on Windows Phone 7    By admin on 5/17/2010 1:55 PM
Thanks for the heads up on this Tiago. I just uploaded an update. Just snag the ZIP from the link again. The change is that you create a new Accelerometer instead of using the Default.

-Andy

Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 5/18/2010 3:34 AM
Hi Andy! Thansk for the quick response. I'm still getting the same error. I deleted the cache to make sure I was using the latest version. The file has the same name AccelerometerPhysics_031710 !?
I'll try to change the code on my side.

I'm also getting a warning when I open the project. It tells me that the project was created on a previous version of the WP dev tools, and that I need to include a certain list of capabilities.

bye,
Tiago Andrade e Silva

Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 5/18/2010 3:39 AM
HI again!
Dispite the warnings, I changed the code as you said and it worked ok :)
//this.sensor = AccelerometerSensor.Default;
this.sensor = new AccelerometerSensor();

bye,
Tiago Andrade e Silva

Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 7/17/2010 1:45 PM
Seems that the Windows Phone 7 project is not compatible with the beta version released last week

Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 10/7/2010 10:33 PM
no worky.

this is depressing for someone from a flash background starting out in XNA and Silverlight .

i thought this would be a cake walk like going from action script to C#. but every tutorial, sample file is built on previous versions that are no longer compatible with XNA 4.0 or WP7.


Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 7/13/2011 11:46 PM
Quick question. Is there a way to manipulate the objects (in this samples case - the ball) position instead of the world's gravity? I'm trying to move an object with the acceleration without manipulating gravity but position cannot be changed as it is not a variable.
Thanks,
Tom

Re: Physics Games in Silverlight on Windows Phone 7    By Anonymous on 11/30/2011 12:02 AM
Thank you Andy! You have done tremendous work and should be proud of your effort!

I am using this product in class.


Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Subscribe
Module Border
RSS   Twitter
Module Border Module Border
Module Border
  Diversions
Module Border

TALKING RAGDOLL
This Windows Phone 7 App was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine. It gets interesting when you import your friends photos and have your way with them!

MORE INFO



DROPPYPOP
This Windows Phone 7 game was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine.
DEMO

MORE INFO



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight 2, the Physics Helper Library,  and the Farseer Physics Engine.
PLAY IT

MORE INFO



DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight 2.
PLAY IT

INFO AND CODE



PHYSICS HELPER DEMOS
These demos were created for the Physics Helper Library, which makes it easy to create physics games and simulations using Expression Blend, Silverlight, and the Farseer Physics Engine.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game took first place in the TeamZoneSports Silverlight Contest. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight 2.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2014 andy.beaulieu.com - Login