[Update] Now supports circle sprites. Also, Andreas Löw, the creator of PhysicsEditor will link to it with the next update of the editor. [/Update]

If you ever created a physics game, for example with my favorite game engine, AndEngine, and wanted to produce a polygonal body, you probably did something that sucked big time. Something like defining your vertices in code. This is

  1. Dirty
  2. Really painful
This is why we looked around and found the PhysicsEditor, a simple to use tool to create an output that describes physic definitions. While iOS integration seemed to work both from the editor into the code, it only provided an AndEngine Exporter-format, but no tool to integrate it back into the engine.
Until today.

 

Capabilities

Here is what it’s capable of:
  • Definitions of (multiple) bodies
  • Definitions of (multiple) fixtures
  • Definitions of polygon shapes
  • Definitions of circle shapes
  • Definition of density, friction and elasticity
  • Definition of dynamic and non-dynamic bodies
  • Definition of sensor and non-sensor fixtures
  • Collision filtering
  • Automatic setting of a body’s user data

 

How to use it

For this part I assume you already know the very basics of AndEngine development. Let’s start from the beginning.

First, download the PhysicsEditor. Open it and import your sprite of choice. I chose the star from the examples project:

Now, draw your physical representation. You might want to use the Shape tracer for that (the wand icon):Now make your settings on the right

and push ‘publish as’. Save your XML somewhere.

Next, it’s time to get the source. Clone the repository using something like git clone git://github.com/ANDLABS-Git/AndEngine-PhysicsEditor-Extension.git. Import the source. Now, make sure you also have the AndEngine and the AndEnginePhysicsBox2DExtension in your workspace. You may have to update this dependencies.

A good match: PhysicsEditor Extension, Box2D Extension, AndEngine and PhysicsEditor Examples

A good match: PhysicsEditor Extension, Box2D Extension, AndEngine and PhysicsEditor Examples

Now in your project, create a new PhysicsEditorLoader-object using the default constructor:
final PhysicsEditorLoader loader = new PhysicsEditorLoader();
Use it to load whatever you want:

try {
loader.load(this, mPhysicsWorld, "xml/", "star.xml", star, true, true);
} catch (IOException e) {
//...
}

The parameters provided are a Context, the PhysicsWorld you want to attach your body to, the base path, the path to your specific definition, the IAreaShape (for example a Sprite) you want your definition to be connected to, whether you want your object’s position to be updated and whether you want your object’s rotation to be updated. And that’s it.

There are some other use cases covered like drawing lines for debugging or loading multiple definitions, but that’s not more than about five keystrokes of additional work. You can take a look at the examples to see what I mean (in case you are curious).
It is possible to use the PhysicsEditor as a tool for level creation. In fact, it enables you to actually ‘draw’ your levels in your graphics tool of choice. Please keep in mind though that the maximum size of an IAreaShape in AndEngine is 2048 pixels, so you may want to use multiple sprites to achieve big levels. Also, memory is low on mobile devices, depending which device your are targeting, you maybe want to think about using a different method than this.

 

A ball jumping on a polygonal physical representation

A ball jumping on a polygonal physical representation

Please keep in mind that this is a very early release that may still contain some bugs and needs some refactoring. Please feel free to leave any issue you discover in the project’s issue tracker.

So far, we have tested the four sample projects on the following devices:

  • Samsung Galaxy Y (2.3.6)
  • Nexus One (2.3.6)
  • Galaxy Nexus (4.0.4)