Build 10 classic Flash games and learn game development along the way with this ultra-fast paced game development course.

If you love this blog, this is the book for you.

Buy the book

Get the source code of 12 commercial Flash games, which have been loaded more than 50 million times!

Learn from real world successful examples.

Get it now

Box2D for Flash Games teaches you how to make Flash physics games from scratch with the most advanced features.

Create the new Flash game smashing hit.

Buy the book

Using RUBE (Really Useful Box2D Editor) in your Flash AS3 projects

I always follow with great interest iforce2d‘s tutorials because they are plenty of interesting ideas. I was inspired by one of such tutorials when I wrote Flying arrows simulation with Box2D and Box2D flying arrows engine – first attempt, so when I realized the author released a full featured Box2D editor called RUBE (Really Useful Box2D Editor) I absolutely wanted to try it.

Following my rule “no pointless reviews”, let me say RUBE is awesome, a must have if you are a Box2D developer. Fullstop.

Now, let me show you how to use it to improve our AS3 coding, since it does not export AS3 code, and it includes more features than the ones included in AS3 v2.1a version.

Although the editor is really powerful and fully documented allowing you to do in a few minutes stuff like this:

I’ll start with a simpler project, building the totem of the first level of Totem destroyer. Here is what I did with RUBE:

And once I export the world in JSON, everything is coded inside, from fixtures to world gravity, from body types to velocities, and so on.

This is the JSON I got from my totem:

Now it’s time to import the JSON in our AS3 class, decode it and build the Box2D world out of it. Since this is just an example, I am retrieving only body types, positions and fixtures, but obviously you can build the whole world.

Before you start, download and install Mike Chamber’s as3corelib which offers a great JSON support.

This is the commented script:

And this is the result:

The totem is done in just a few lines of code, but obviously the most interesting thing is I would have been able to build a totem made by 1000 bricks in exactly the same amount of lines.

Download the source code with all required libraries. I am also going to create a RUBE to AS3 class to have the ultimate Box2D editor.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)
Loading ... Loading ...
Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 18 comments

  1. Jimmie

    on December 19, 2012 at 8:42 pm

    Throws an Error for me:

    Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://www.emanueleferonato.com/2012/12/19/using-rube-really-useful-box2d-editor-in-your-flash-as3-projects/totem.json
    at Main()

    Looks like the url for that file doesn’t exist or isn’t loading.

  2. Diogo

    on December 19, 2012 at 9:21 pm

    The first image of the post is not showing, and the flash is an enpty gray area :(

  3. Emanuele Feronato

    on December 19, 2012 at 9:51 pm

    fixed! thank you!!

  4. payampap

    on December 20, 2012 at 11:59 am

    Thank You
    Usefull

  5. iforce2d

    on December 20, 2012 at 2:03 pm

    Wow, that was fast. Nice job!

  6. Using RUBE (Really Useful Box2D Editor) in your Flash AS3 projects – Emanuele Feronato « eaflash

    on December 21, 2012 at 11:24 am

    [...] on http://www.emanueleferonato.com Share this:TwitterFacebookLike this:LikeBe the first to like [...]

  7. cnsoft

    on December 22, 2012 at 3:54 pm

    it seems that adobe has provide original json process function. no need use that as3corelib.

  8. codeBeast

    on December 23, 2012 at 5:31 pm

    1. new json function is for flash player 11 so it’s still a good idea to use the as3corelib as you need to make games available to the widest possible audience.

    2. I am mucking around with the editor an yes it’s amazing. I hope you post a few more tutorials with regards collision testing etc… or does that have to be taken care of like always in Box2d and this is merely a tool for developing the visuals.

    3. Performance: Is the json file translated straight to box2d code and the performance therefore exactly the same as normal Box2d ie: Slow on mobile???

  9. Husky

    on January 6, 2013 at 5:12 pm

    Pretty cool!

  10. Jacques

    on January 8, 2013 at 8:04 pm

    Emanuele, this is great. I didn’t know about RUBE until this post. I’m curious to know how you would compare this tool to using the World Construction Kit (http://www.sideroller.com/wck/)? The WCK is my general go-to framework for my Box2D projects, but with a good RUBE to AS3 class, I might make the switch :)

  11. Julio

    on February 9, 2013 at 6:19 am

    hey there just a question

    can i use this editor to get the code and use it in javascript box2dweb???

    do you know any box2dweb editor like this?

    thanks and sorry for my bad english =D

  12. iforce2d

    on February 15, 2013 at 12:44 pm

    Julio
    There are some box2dweb examples on the main page, and in the trial download :)

  13. Simon

    on March 21, 2013 at 1:27 pm

    Hi Emaneuele, thanks for posting the tutorial it’s been a great help. I’ve run into a problem though after I bought R.U.B.E and am trying to load my own level:

    After parsing the JSON file and creating the box2d world everything is upside down, even with the y-pos check you have when creating each body. Anything I may have missed?

  14. jonathan

    on March 26, 2013 at 7:51 pm

    Hey Emanuele,

    Thank you for all the post you’ve done, I mean, about everything. This is just very generous.
    Thank to this post, I’ve decided to use RUBE to create my world.

    I’ve adapted your code to work with customs body (multiple fixtures).
    There was only one line in your code that I did’nt get:

    “// look at body y position to prevent it to be upside down”

    As my world was looking good, mostly very similar shapes, I didn’t pay attention that they were upside down…
    But still at the right position…

    Could you explain how to avois that? I mean, if you have few secondes… of course.
    Thank you again anyway.

    Jonathan

  15. Gilles

    on April 7, 2013 at 11:23 am

    Hey,

    Awesome stuff, I’m suprised that tool is not really well known.
    I saw you can also have custom properties to your objects. I’ll work on some full starling/box2d integration in my next game project.

    Small question : I didn’t try http://www.sideroller.com/wck/. Is it that faster than as3 box2d lib, because I don’t see much update since a year.

    Nice work, cheers.

  16. Gilles

    on April 7, 2013 at 11:23 am

    Hey,

    Awesome stuff, I’m suprised that tool is not really well known.
    I saw you can also have custom properties to your objects. I’ll work on some full starling/box2d integration in my next game project.

    Small question : I didn’t try http://www.sideroller.com/wck/. Is it that faster than as3 box2d lib, because I don’t see much update since a year.

    Nice work, cheers.

  17. Sharat

    on May 2, 2013 at 10:17 am

    Hi Emaanuele,

    I have tried your material. It was very useful to integrate JSON into flash. I was wondering. I get an error when i include a circle in the scene. Do i have to define circle as well because the defection is only for polygons. How can i load all the data of the JSON file including density, restitution and friction. I could not get to do that and also do i acess the objects that have been created with the JSON file.
    Thank you very much for the light on this topic.
    Regards,
    Sharat

  18. Sharat

    on May 2, 2013 at 11:09 am

    Solved the problem by making different objects before JSONLoaded event. Really awesome. Thanks you so much for the Light towards this topic.

    Regards,
    Sharat