SpriteHand
Module Border
  Farseer, Far-Easier: Physics Helper for Blend and Silverlight
Module Border
Location: BlogsAndy's Blog    
Posted by: host 9/13/2008 12:04 PM

 

UPDATE 10/18/2008: There is a new version of the Physics Helper Controls! More info here...

If you have tried creating a Silverlight game using the Farseer Physics engine, you may have found it a bit difficult to translate your game sprites into Farseer Polygon geometries. Another challenge is lining up Farseer Joint elements with your game elements - because there is no visual link between your design tool (generally Expression Blend) and the Farseer objects.

After toying with this issue through a few small games, and trying different strategies, I've tried a new approach ...

Overview

I’ve created a small library of Silverlight User Controls which allow for quick design of physics-based applications using Expression Blend 2.5 as the design surface and the Farseer Physics Engine for simulations.  Using these “Physics Helper” controls, you can draw out physics shapes, including joints, and have those objects translated into Farseer physics elements with little or no coding.

 

Intro Videos

These intro videos show how you can design and run physics simulations in Blend 2.5.

VIDEO 1: Designing Farseer Physics in Blend 2.5

VIDEO 2: Advanced Farseer Physics in Blend 2.5

 

Download

Physics Helper Version 1.0.0.1 Alpha (includes source and demos below)

Demos

These demos were created with minimal or no coding using the Physics Helper:

Demo 1: Egg on Hill
Demo 2: Car on Ramp
Demo 3: Simple Physics Game



A Walkthrough: Using the Physics Helper with Blend 2.5

1.     First, download the PhysicsHelper library (link above). You will also need Visual Studio 2008 with Silverlight Tools and Expression Blend, all available at www.silverlight.net.

2.     In Visual Studio, create a new Silverlight Application.

3.     Add a reference to PhysicsHelper.dll and FarseerGames.FarseerPhysics.dll in the download from Step 1 above.

4.     In Page.xaml, change the LayoutRoot element from a Grid to a Canvas to so it looks like so:

<Canvas x:Name="LayoutRoot" Background="White">
Canvas>

5.     Open Page.xaml in Blend by right-clicking it and selecting "Open in Expression Blend."

6.     Select the Ellipse Tool and draw out a circle. At the top of the Properties window, name the Ellipse "ball."

7.     Select the Pen Tool and draw out a path that looks like a ramp. Name the path "ramp." You should now have something like so:

http://www.andybeaulieu.com/Portals/1/PhysicsHelperDemo1.png

8.     Select the “Asset Library” from the bottom of the Blend Toolbox, and then select the “Custom Controls” Tab:

http://www.andybeaulieu.com/Portals/1/PhysicsHelperDemo2.png

9.     Drag a PhysicsController onto the Canvas. Then, at the Bottom of the Properties window, expand the Miscellaneous Category and set the “AutoAddCanvasObjects” to true and “GravityVertical” to 500.
http://www.andybeaulieu.com/Portals/1/PhysicsHelperDemo3.png

10.  Go back to the Asset Library in the toolbox and drag a PhysicsStaticHolder onto the Canvas. In the properties window, under Miscellaneous Category, set the “Body” property of the PhysicsStaticHolder to “ramp” (this makes the ramp stay in place like a “static” body).

11.  Select File/Save to save everything.

12.  Run the project by hitting F5.

Physics Helper Known Issues

Note that I consider this an initial “Alpha” release of the Physics Helper! There are some issues that I will describe below.

  1. This is really just a preliminary Alpha proof of concept, so while it works for many situations, there is definite room for refactoring and redesign!
  2.  If you rotate or otherwise transform an object in Blend, the object will lose that rotation when running, and the Boundary determination will be incorrect.
  3. The algorithm to determine the shape of a XAML element needs enhancement! While it works for a great many shape outlines, it is quite possible to create shapes can hide from the algorithm, and you end up with funky collisions. To Debug this problem, set the PhysicsController.IsDebugMode property to “True”.
  4. Blend 2.5 Preview does not yet handle CategoryAttributes (but the RTW version of Blend 2.5 will)… So the Physics properties are all stuck under “Miscellaneous” Category for now in Blend.

 

About the Farseer Physics Engine

Farseer is an easy to use, open source physics engine created by Jeff Weber and later ported to Silverlight by Bill Reiss. I’ve used Farseer to build Silverlight games and demos such as Hook Shot, Sort the Foobars, and the Polygon Demo.

UPDATE 10/18/2008: There is a new version of the Physics Helper Controls! More info here...

Permalink |  Trackback

Comments (5)   Add Comment
Re: Farseer, Far-Easier: Physics Helper for Blend and Silverlight    By Anonymous on 9/14/2008 1:13 PM
Looks amazing! Haven't tried it out yet, but I will :)

Great job!

Re: Farseer, Far-Easier: Physics Helper for Blend and Silverlight    By Anonymous on 9/16/2008 7:21 AM
Ok I'm impressed...

Re: Farseer, Far-Easier: Physics Helper for Blend and Silverlight    By Anonymous on 9/16/2008 1:53 PM
WONDERFUL!

Re: Farseer, Far-Easier: Physics Helper for Blend and Silverlight    By Anonymous on 10/15/2008 1:43 AM
Hi there, this is really cool!

Just as you say, I had a look at the Farseer engine and first look, it looks pretty daunting so I reckon you're doing a great thing here.

Might just be me but, can I use the Physics helper to add objects dynamically from code? I'm adding an UI Element to the canvas and use the controller.AddPhysicBody() but it's not getting picked up...

Keep up the good work.


Physics Helper for Silverlight, Blend and Farseer    By TrackBack on 3/26/2009 3:13 AM
Physics Helper for Silverlight, Blend and Farseer
# Marc: My Words


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


PHYSAMAJIG
This Windows app was created using Physics Helper XAML, and the Farseer Physics Engine.
DOWNLOAD

MORE INFO



TALKING RAGDOLL
This Windows Phone 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



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight , 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.
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 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 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 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight.
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