Have fun and help me to get to 1,000,000 downloads!

Create REAL explosions with Box2D – adding textures

Emanuele Feronato Actionscript 3, Box2D, Flash

Ok, you asked it, now you have it. Now the Box2D explosion prototype features bitmap textures and a commented source code.

I have to say a big thank you to Antoan Angelov for his version of the slicing engine as he allowed me to manage textures with no hassle.

So now basically an explosion is a number of cuts at a random angle, all passing for the same point, which is the origin of the explosion. Then, every resulting slice will have a linear velocity according to the distance between the center of the slice mass and the origin of the explosion.

So this is what you’ll get:

Click on a crate to make it explode.

And this is the full, commented source code:

and this is userData class:

And now let me see what kind of games can you make using this concept.

Download the source code.

From null to full HTML5 cross platform game

I will take you by hand from the bare bones of JavaScript programming through the creation of a full cross platform HTML5 game, with detailed explainations and source code.

If you don't know where to start, then From null to full HTML5 cross platform game is the book for you.

Comments 15

  1. Amit

    I am not a flash developer…but still i am following you coz i get ideas from you. i also enjoy ur posts and demos. I like to play with ur demos ;) can u add “Reply” button to demos ?? coz i need to refresh the page, if i want to play with demo again and again :(

  2. Simon

    Wow – that is pretty awesome. I wan’t to make a building demolition game with this. The only problem is my inability to finish projects. But thank you for this, as well as all your other inspiring articles.

  3. Michael

    Great job Erin & Antoan! True source of inspiration for game developers!

    I look forward to try and making this work on the iPhone

  4. MC

    Emanuele, have you ever considered to create a small game framework in as3? Or a small customizable library with useful functions like: create/delete, explode and slice box2d objects?

  5. Chris

    Awesome, very super cool!

    I’ll be trying this out with my Android game- even being able to do one such explosion would add a ton of realism to some of the levels.

    You’re giving us tools/ideas to make awesome games!

  6. Pingback: All you need to know about how to write Box2D game | Artits Rastas

  7. Jamie

    Hey just trying to implement this in something, im trying to get it to work when something collides against the box, however if i change clickedBody to be a passed in body, it doesn’t work and i cannot see why. It gets an error due to removal =s

  8. Molano

    is this make sense ? what do u think @emanuele

    bodyDef1.type = b2Body.b2_staticBody;
    color_block = new cblock();

    bodyDef1.userData = {assetName:”cblock”,assetSprite:color_block};
    color_block.x = posx;
    color_block.y =posy;

  9. Piotr Kundu

    A lot of bitching has been done about Emanuele on his coding style, books and source code for sales. There are at least one more coding style than there are developers in the world and the “Not invented here” signal strike me too. You could take this code more OOP or TDD and DI, but the fact is that the algoritm is there! The solution is not obscured by a choice of methodology or usage of advanced tricks. I’m using bits and peaces in a C++ application and I’m guessing this is AS3 and Flash? I couldn’t care less, since everything is laid out and I’m happy people like Emanuele spend their time putting stuff on the web. I’m happy that people like Erin write open source like Box2D making bird companies rich.

  10. gd

    Hey, noob question. very new to box2d. where exactly do I put my flash sprites into the code, been trying to do it for 2 days now. no luck.

    any help would be awesome.

  11. Graham

    This is really something. It also works in the latest Box2D.

    I implemented it into a situation with a bunch of overhead and the box seems to freeze in mid-air and then pause a second, then explode.

    This would be fantastic to get to happen to objects in motion, and somehow trim the processing power.

    I’ll see what I can come up with.

Leave a Reply

Your email address will not be published. Required fields are marked *