Project Description

The Physics Helper for Blend, Silverlight and Windows Phone 7 contains several Behaviors which allow you to draw objects in Expression Blend 4, and have those objects translated into Physics objects using the Farseer Physics Engine. This can be a great timesaver for creating games, as it is traditionally difficult to line up underlying physics bodies and geometries with your Blend artwork.


NOTE: INTERESTED IN WINDOWS 8 METRO DEVELOPMENT?
Check out the port of the Physics Helper to Physics Helper XAML for Metro style app development in C# or VB.

New to Version 4 of the Physics Helper:

Intro Videos

Watch these short videos to see how easy it can be to design physics using Expression Blend 3, Silverlight 3, and the Physics Helper Behaviors:

VIDEO ON VERSION 4.0 VIEW
This is an intro video on using the Behaviors to apply Physics in Expression Blend.

VIDEO ON VERSION 3.0 VIEW
This is an intro video on using the Behaviors to apply Physics in Expression Blend.

VIDEO ON VERSION 3.0 "JOINTS + PROGRAMMING" VIEW
A more advanced video on using Behaviors to create Joints and accessing objects via code-behind.

CODING4FUN SHOW VIEW
Brian Peek interviews Andy Beaulieu on the Physics Helper. Note that this demos Version 1, which is based on the User Controls instead of Behaviors.

MIX09 SHOW OFF! VIEW
The Physics Helper Library took 1st Place at the 2009 MIX Show Off! Event. This is the winning video.

Demos

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

DEMOS for Version 4.0

DEMOS for Version 3.0


Other Documentation Sources

*Farseer Physics Manual
*Creating a Shuffleboard Game for Windows Phone 7 Using Silverlight
*Creating a Pinball Game in Silverlight

Notes

Coding Techniques

Behaviors are great, but it would be difficult to complete a full game using only the behaviors included in the library. So at some point, you will need to add code to do AI, control levels and game state, and other tasks. To do this more advanced coding you will need to get access to the underlying Physics simulation and Physics bodies. Here are some pointers to get started with that:

Once you drop a PhysicsController Behavior onto your main Canvas, you can later get a reference to that Physics Controller (the object that contains the simulation context) in code. Suppose your main Canvas is named "LayoutRoot" then you can get a reference as follows:

PhysicsControllerMain _physicsController = LayoutRoot.GetValue(PhysicsControllerMain.PhysicsControllerProperty) as PhysicsControllerMain; 


After you have a reference to the PhysicsController, you can modify any of the Farseer Physics Geometry or Body objects by getting a reference through the PhysicsObjects dictionary. You can also get a reference to the main Farseer Physics simulation to change things such as gravity (for details on the classes provided by the Farseer Physics Engine, go here):

_physicsController.PhysicsObjects["ball"].BodyObject.IsStatic = false;
_physicsController.Simulator.Gravity = new Vector2(0, 500);


In the newer versions of Farseer Physics, some properties are nested inside Fixtures - which are the geometry shapes used for collision. You can get at these through the FixtureList...

            foreach (PhysicsSprite spr in _physicsController.PhysicsObjects.Values)
            {
                    foreach (Fixture f in spr.BodyObject.FixtureList)
                    {
                        // grapple hook should collide with both bottom and boxes
                        f.CollisionCategories = Category.Cat2;
                        f.CollidesWith = Category.Cat1;
                    }                
            }


You can also handle events, such as the Collision event, raised by the PhysicsController when two physics geometries collide:

    _physicsController.Collision += new PhysicsControllerMain.CollisionHandler(_physicsController_Collision);

    void _physicsController_Collision(PhysicsSprite sprite1, PhysicsSprite sprite2)
    {
        if (sprite1 == sprShip && sprite2.Name.StartsWith("asteroid"))
        {
            // blow up the ship
        }
    }


... and you can also get a reference to the oringal XAML UI Element using the uiElement property of the Physics Object:

Ellipse ball = _physicsController.PhysicsObjects["ball"].uiElement as Ellipse;
ball.Fill = new SolidColorBrush(Colors.Red);




The Physics Helper is currently in Beta and is still a work in progress. You can find out more at Andy Beaulieu's blog: Here and Here