Box2D plugin

Top  Previous  Next

Rajoelison Andry Herizo is one of the Winter 2010 contest winners; he has kindly accepted to answer a few questions about his Box2D plugin entry.

 

Q: What is Box2D?

A: Box2D is a popular open source 2D rigid body physics engine created by Erin Catto. As such, it can be used in games to simulate the movement of rigid bodies in two dimensions. The Box2D home page can be accessed at http://www.box2d.org

 

Q: Why did you decide to incorporate Box2D into GameStudio?

A: One day, I searched the forum for a way to create a 2D physics game with GameStudio, and I didn’t find any (that uses a 2D physics engine), so I thought to create a GameStudio plugin for an existing physics engine. I chose Box2D because I think it is well done and very popular so searching for help would not be hard. I also wanted to give the GameStudio community the ability to create the same amazing things as those created with other competitor products in the area of 2D physics game.

 

Q: Could you describe some of the demos you’ve bundled with the plug-in and tell us what features they’re showcasing?

A: The demos were mainly created to test if the plugin is running really like it should, so I chose to implement tests that are known to be ok, used by other languages or by Box2D itself (Box2C C++ testbed and Box2DFlash - http://box2dflash.sourceforge.net/). The demos can also be used as a documentation to see how to perform certain tasks with Box2D and Lite-C. Below are some list of the demos and the features implemented in them:

 

* Test framework (test.h): Using the mouse joint and a “world query callback” to implement mouse picking and dragging on bodies.

*  Ragdoll test (test_ragdoll.h): Bodies creation and attachment with joints.

* Compound test (test_compound.h): Creation of bodies with complex shapes (with default shapes and with polygon vertices) by combining many shapes in a body (fixtures).

* Crank, Gears, Pulley (test_crank.h, test_gears.h, test_pulley.h): Demonstration of different joint types.

* Bridge (test_bridge.h): Simulation of a bridge by attaching bodies with joints.

* Stacked box, Stacked Circles (test_stacked_box.h, test_stacked_circle.h): Demonstration of continuous collision detection on small fast moving bodies.

* Body types (test_body_types.h): Showcases different body types and their behaviors (Static, Dynamic and Kinematic). More about the body types can be seen in the Box2D manual.

* Breakable (test_breakable.h): Implementation of a contact listener “post solve callback” to simulate a breakable body when receiving a certain amount of external force (Deletion of a shape that composes a body and creation of another body with it).

* One sided platform (test_one_sided_platform.h): Implementation of a contact listener “pre solve callback” to filter collision only on one side of a body.

 

Q: Is it possible for us to create custom 2D shapes? If the answer is affirmative, how do we do that?

A: Yes, there are many ways to create custom 2D shapes, for example compositing a shape with many other shapes (creating many fixtures on a body) or creating custom polygon with vertices. Vertices are defined using an array of Gamestudio VECTOR. The maximum size of the array is 8 (It is the default configuration of Box2D, but the manual says that it is ok for most polygons). More info on shapes could be found in the Box2D manual (http://www.box2d.org/manual.html), and in the testbed file test_compound.h.

 

Q: From your experience, how many standard 2D objects can be visible on the screen at the same time without killing the frame rate?

A: It is hard to answer that question, because it depends on many things, like the method chosen to implement the drawing (with lines, like in the test, with panel, or with sprite entities), or the Box2D settings (continuous collision detection, position and velocity iteration, and so on). But what is safe to say is it can be used to create many of your 2D physics game Idea. With sprite entities as the rendering method, I had 60 fps with 1000 entities visible on the screen, so I think that it is ok for most projects.

 

Q: Can you tell us the name of a successful game title that makes heavy use of a 2D physics engine?

A: Well, there are many games that mainly use 2D physics engine. Some of them are Crayon Physics Deluxe (http://www.crayonphysics.com/) and the very popular Angry Birds (http://www.rovio.com/index.php?page=angry-birds), they use Box2D physics system. But there are also around the internet many other good games that use 2D physics.

Q: Do you have any future plans for this project?

A: Actually, the plugin is wrapping all the default Box2D functions, but there are also many other cool stuffs that I plan to implement, like buoyancy and radial gravity (I saw it in a flash Box2D implementation). The plugin is also not bound to any rendering method: I used it myself with different methods, but I think it would be good to include some functions built on top of the actual system that are specific to some rendering methods.

 

Q: Please give us a few tips for the beginners.

A: It is really hard for me to answer this question because I consider myself a beginner. But what can I say is that the most common and the worst enemy of beginner developers is motivation. At the beginning of a project, motivation is at its peak, so it is easy to think that nothing is impossible. But keeping motivation is really hard, even for experienced developers. So, for a successful project, it is extremely vital to plan well what can really be done and at maximum try to stick with the established plan. And especially for Gamestudio beginners: finish the workshops, read the AUM and ask questions in the forum.

 

Thank you a lot, Herizo!