[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
- Dirty
- Really painful
Capabilities
- 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.
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.
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)
2012/04/23 at 16:19
Yeah, PhysicsEditor is a GREAT piece of software! I’m curretly using it in my new motocross game and I could NOT make it without this editor :)
2012/04/23 at 16:26
Hey Pawel,
long time no comment, great to have you back!
Indeed, it really provides a solid foundation for almost any form of Box 2D development. It’d have been really hard to write an editor like this on one own (but even harder to edit Box 2D polygons in code all the time). Kudos to Andreas!
Best regards
Johannes
2012/04/24 at 06:30
Nice extension – good job! ;-)
I just wonder what was so bad about the included one? Was it too well hidden in the examples folder? Or did it not fit your needs?
2012/04/24 at 07:05
Thank you for your comment Andreas!
I didn’t realize that there actually is an examples folder coming with the PhysicsEditor. Where can I find it?
Best regards
Johannes
2012/04/24 at 07:30
On MacOS it’s inside the .dmg file – on windows it’s installed inside the app’s folder (C:\Program Files (x86)\PhysicsEditor)
Ok – I see that I need to find a better place – or at least add a hint where to find it….. ;-)
2012/04/24 at 08:15
Ah, now I found it. Could have looked into the .dmg earlier. It’s interesting to see the differences. Your parser is targeting the GLES 1.1 branch, so I can say that it somehow didn’t fit my needs. Maybe you could ask Nicolas to make it an official extension, this probably would be the way to get most people’s attention.
2012/04/27 at 15:10
how I can add the project to eclipse?
2012/04/28 at 09:23
Hi Daniel,
this should work with new-> Android Project-> Create project from existing source.
Best regards
Johannes
2012/04/28 at 13:22
Thank you so much!
2012/04/30 at 18:43
Hi Johannes and thanks for your extension!
Just a few questions :) In PhysicsEditorLoader.java eclipse doesn’t seem to like “loadLevelFromAsset(pContext, pAssetPath);” – The method loadLevelFromAsset(AssetManager, String) in the type LevelLoader is not applicable for the arguments (Context, String).
Also it doesn’t like void in “public void onLoadEntity(String pEntityName, Attributes pAttributes) { ” – The return type is incompatible with IEntityLoader.onLoadEntity(String, Attributes).
Any ideas what’s wrong with it?
Thanks again! :)
2012/05/01 at 12:19
Hi Roger,
I just adjusted it to the most recent changes to AndEngine, everything should work fine now.
Best regards
Johannes
2012/05/02 at 13:50
When I try to run the examples I get the following error:
[05.02.2012 15:46:31 – AndEnginePhysicsLoaderExtension] Installing AndEnginePhysicsLoaderExtension.apk …
[05.02.2012 15:46:35 – AndEnginePhysicsLoaderExtension] Success!
[05.02.2012 15:46:35 – AndEngine] Could not find AndEngine.apk!
[05.02.2012 15:46:35 – AndEnginePhysicsBox2DExtension] Could not find AndEnginePhysicsBox2DExtension.apk!
Thanks!
2012/05/03 at 11:20
Hi Dani,
I’ve seen this as warnings in other projects before but not as errors. Did you add the AndEngine and Box2DExtension properly?
Best regards
Johannes
2012/05/21 at 05:42
Hey. I stumbled upon this amazing gem but I’m having difficulty using it. I’m working on a game and I originally had Rectangular bounds for one of my sprites. I used the PhysicsEditor to export the XML with the complex bounds. After getting the code in, I there was no collision. I then tried out all the examples. I had difficulty and I documented the errors here.
https://github.com/ANDLABS-Git/AndEngine-PhysicsEditor-Extension-Examples/issues/1
Could you help me out or perhaps make another post about the Physics Editor Extension. I’m curious about altering the rigidbody properties of a complex shape (changing velocity, angular rotation etc…). I really want to integrate this tool into my project. This type of tool can simply take android gaming to a whole new level.
2012/05/21 at 07:58
Hi Tom,
thank you for your comment. Please have a look at my comment to the issue.
Best regards
Johannes
2012/08/08 at 20:29
As Roger said:
In PhysicsEditorLoader.java eclipse doesn’t seem to like “loadLevelFromAsset(pContext, pAssetPath);” – The method loadLevelFromAsset(AssetManager, String) in the type LevelLoader is not applicable for the arguments (Context, String).
Also it doesn’t like void in “public void onLoadEntity(String pEntityName, Attributes pAttributes) { ” – The return type is incompatible with IEntityLoader.onLoadEntity(String, Attributes).
I can’t solve this errors. Help please.
Thanks
2012/12/01 at 21:47
Thanks for that, have you been thinking about implementing it for latest GLES2 Anchor Center AndEngine branch?
2012/12/06 at 19:42
You’re welcome. Yes, I have. But it will take some time since my priorities are on some other project first. But since an open source project: Feel free to commit any changes you make :)
Best regards
Johannes
2013/02/09 at 18:40
An AndEngine GLES2 AC Version would be great.
I hope you can find some time to create one.
I would love to do it myself but unfortunately I neither understand your source code nor the AndEngine well enough.
And I have no idea how I’d have to change it to get it to work with AnchorCenter
2013/04/21 at 17:33
Hi Stefan,
I’m sorry to say that this will probably still take some time.
Regards,
Johannes
2012/12/11 at 14:53
Hi, thanks for tutorial and to Andreas Lowe for texture packer and physics editor, I was just wondering how to use PE with Tiled/animated sprites, if anyone has an idea….
2013/04/28 at 15:28
Hello, what are you using for your level editor? I am using Andengine GLES2 Anchor Center. Thanks
2013/04/30 at 13:05
Hi Jr,
the PhysicsEditor’s output is XML, the extension I wrote uses currently only the GLES2 branch.
Regards,
Johannes
2013/05/14 at 03:17
This looks great. Looking forward to trying it out.
2013/07/01 at 10:48
hi, I am getting problem with andengine gles2 and physics editor. when i use multiple xml in 1 level first xml works fine and remaining have issue about body creation and position, mean sometime body not created and somtime it created but with different position and image on different position.
someone told me that i am using wrong version of physics editor.
I am using Andengine Gles2. please guide me about which version of physics editor i should use for compatibility.?
2013/07/12 at 15:52
Hi Zeeshan,
since the first XML works fine, this probably isn’t a problem of the version. Are you calling reset() after the first XML?
Regards,
Johannes
2013/07/15 at 22:52
Thanks for replying. My problem solved by recreating xml and calling reset. Thanks for such a fantastic editor.
2013/07/17 at 09:34
Hi Johannes:
I’m using PhysicsEditor and i want to touch and drag a body created with it. My problem is that i don’t know how to refer to the body created with PhysicsEditor. I use this lines to create it:
final PhysicsEditorLoader loader = new PhysicsEditorLoader();
try {
loader.load(this, mPhysicsWorld, “xml/simple_asset.xml”, mBigAsset,false, false);
} catch (IOException e) {
e.printStackTrace();
}
When you create a body in AndEngine you can refer to it this way:
body.setLinearVelocity(new Vector2(10,0));
How can i do that with a body created with PhysicsEditor?
Thank you very much.
2013/08/26 at 22:22
Hi Juan,
please excuse my late reply.
You can use getBody(final String pName) to retrieve a loaded body or getBodies() for all bodies.
Best regards,
Johannes
2014/03/17 at 05:38
please explain full code. how to use joint like Revolute Joint its need body how to use physics editor body.
2013/08/29 at 16:55
I use both the PhysicsEditor and TexturePacker. Great tools. Keep up the good work. Thanks tons.
2013/12/05 at 08:02
Hi Jaun, when i make body dynamic in physic editor and make another dynamic body from andengine box2d code then these two bodies does not collide sometime and collide sometime with very wrong position. When i make physics editor body static then everything works fine.
Could you tell me where i am getting wrong while creating dynamic body. Also when i create dynamic body i set body update position and rotation disable.
2014/03/17 at 05:52
how to use like joints
carbody = new Sprite(CAMERA_WIDTH/2-10, CAMERA_HEIGHT/2-70, bodyTextureRegion, this.mEngine.getVertexBufferObjectManager());
rjd2 = new RevoluteJointDef();
rjd2.initialize(wbody2, Body, wbody2.getWorldCenter());
rjd2.collideConnected=false;
rjd2.motorSpeed=1f;
rjd2.maxMotorTorque=200;
rjd2.enableMotor=false;
2014/03/28 at 07:20
Hey, i use the physicseditor with andengine. when i create a body using the PhysicsEditorExtension, the body and the sprite have different positions. The origin of the Sprite is the center of the body. How can i solve it?
2014/03/31 at 23:22
Hi Alex,
which branch of AndEngine are you using? AnchorCenter?
BR
Johannes
2016/05/12 at 17:53
I using Android Studio! When i import the project, a message about the missing gradle appears. I dont know what i can do. Please. Help!
2016/05/23 at 09:52
Hi Ze,
thank you for your comment. Unfortunately I don’t have the resources to work on this project anymore. Therefore it does support neither android studio nor the anchor center branch of AndEngine.
Best regards,
Johannes