Box2D....

Monkey Archive Forums/Monkey Projects/Box2D....

Brucey(Posted 2011) [#1]
Here's a small example of a possible box2d implementation in Monkey...



... running in Flash, using the AS3 Box2D framework.

The Monkey source:


I've wrapped the framework in two layers... one is the (kind of) abstract monkey interface, which hides the raw, target-specific implementation + glue.

It runs verrrrry smoothly indeed ! :-)

It took me a day (well, what else is there to do on a Sunday?) to get my head around how this might work, and then to get the basics down. If I hadn't have spent a few hours not realising that my OnUpdate() wasn't actually being called, and that I also had to apply a body transform to the vertices (for drawing), I could have been much further on... pah!

I had to modify trans, to support multiple "PATHS" for mxmlc (the -sp option), since my module includes the AS3 source for Box2D, which is compiled in during the build.
It now does something like this:
Execute "mxmlc -static-link-runtime-shared-libraries=true -sp . " + FLASH_MODS + " -- MonkeyGame.as"

from which there is a config option where you can define:
FLASH_MODS="MODULES_PATH/bah/box2d/as"

MODULES_PATH is replaced with the root modules folder wherever trans is...
( ${} ) doesn't work here, as MODULES_PATH is not an environment variable :-p

The idea behind a multi-layer wrap is that, in theory, one can simply add the relevant other targets+glue at some point.

Things to note :
* It's hard to add new functionality in the way of modules, without hacking big changes into (at least) trans.
* It's not impossible to integrate existing frameworks into Monkey - it just requires a lot of work at the moment.

fun fun...

<EDIT> amended for my own foolishness to add SetUpdateRate()...
<EDIT> updated original image to show complete example in action...


Xaron(Posted 2011) [#2]
Uh that's incredible cool. Actually I work on a clean Box2d port for Monkey but currently port chipmunk physics (with help of Mark) first because it's more lightweight and has almost the power Box2d has.


Brucey(Posted 2011) [#3]
Now that I have read some of the Monkey documentation (haw haw), development of the first app has been very quick to get it running nicely. In fact, most of the StackTest port from the AS3 code was a case of copy/paste/tweak.

You can see more about the working example here. (and screenshot in the first post)

I split out the Box2D code from the main "App", in an effort to tidy things up a bit :

It even supports Arrays for creation of polygons - this is easy for AS3, because Monkey fortunately uses the native Array type. Not sure how this will integrate with other languages...

Obviously, there's much more required to implement - joints, contacts, etc - but it gives a good idea of potential.


xzess(Posted 2011) [#4]
Great work as always Brucey :)

Would you share you module or do you have a download link?