Recently I was interested to work with the Physics Helper for Silverlight. I saw couple of demos on net which uses the Physics library for Silverlight to create good animations with Friction logic. Yeah, friction. You can drop a ball on a surface which will bounce over that surface. I found it very interesting and thought to create a Simple Demo for it.
Here I will demonstrate you creating a Sample Application using Expression Blend. You don't have to write a Single line of Code using Visual Studio.
Is it? Yes, lets start doing that.
You need the following tools installed in your development environment before going to the next steps:
Setting up the Project in Expression Blend:
Once you downloaded and installed them properly open your Expression Blend and create a new Silverlight Project with Website. Select the proper location to create the Project and provide a good name for your solution. Here, I am creating "Silverlight 4 Physics Demo" as the solution name.
Once you are done creating the project, go to the Assets tab in Expression Blend and search for "Spritehand.FarseerHelper.dll" under the "Location". If you are unable to find it there means your Physics Helper library was not installed properly. Then manually add them as dll reference in your project. Once you find the "Spritehand.FarseerHelper.dll" in your assets tab, click on it and you will find some controls visible in the right panel. They are "CameraController", "CameraLayer", "PhysicsController", "PhysicsJoint" and "PhysicsStaticHolder". Look into the below snapshot. We will use only two among them in this example "PhysicsController" and "PhysicsStaticHolder".
PhysicsController is responsible for motion in Horizontal or Vertical way to your object or to create a collision among your objects. PhysicsStaticHolder mentions it's work in it's name. Yup, it's binded to a solid object or a group of objects where your item will drop having some velocity and friction.
Running the Demo:
All the design and creation part is ready to give a demo now. Press 'F5' inside the Expression Blend. It will build your project and run the application inside your default browser. In a short time you will see the ball is falling down from top to the valley along the surface.
Hey, what's going on there? The ball is running along the path. See the rotation of the ball. Yes, the ball is rotating while moving forward.
Due to the speed of the ball it will go up to the next surface wall and then again fall down. It will go for some moment and then the ball will set it's position to the bottom of the surface and no movement will be visible after that.
Once the ball take it's own position in the surface, click the ball and try to drag it up. Wao, we can drag the ball too. It will look like the ball was dragged with a rope. You can drop it anywhere in the surface and you will see the rotation along the path. Now, if you drop the ball outside the surface area by changing the UI a bit, you will notice that the ball is falling down and due to no surface in it's way it will be gone.
Hope you really enjoyed the article. It gave you a basic understanding to start working on the Silverlight using the Physics Helper library. You can use this library to create Silverlight games. If you explore it more from code, you will get a huge API's to develop you business need.
Here are some samples posted in the Blog of Andy Beaulieu
, who is the Coordinator of the Physics Helper Library hosted in CodePlex
. Click on the images below and it will run the respective application. Watch out the demos and you will know what you can achieve using Silverlight and the Physics library.
Don't forget to share your feedbacks. Cheers...