Creation of a Flash artillery game using Box2D – part 2: removing bullets

This is the second part of Creation of a Flash artillery game using Box2D… one reader asked for a function to make blocks (bullets) disappear after 10 seconds or any given time.

I found the question interesting, and here I am writing something about removing bullets.

To introduce timed bullets, I only need another class to keep track of passed time and pass a flag to the main class when the bullet “gets old”.

This is the new class called

Next step is assign the class to every new bullet and periodically check for bullet age and eventually remove it.

And this is the result… same as Creation of a Flash artillery game using Box2D but boxes disappear after 10 seconds.

Download the source code.

  • surely dispatching an event from the bullet and listening for it from the main class and then removing once received would be a better approach?

  • You can fly by holding UP and rapidly clicking bottom of the flash screen

  • Platon Skedow

    The best way to fix rotation of a hero – set
    bodyDef.fixedRotation = true;
    instead of calling each time bb.m_sweep.a=0;

  • @ Astro75 :

    Let’s call that the “Jetpack effect“.

  • Guest

    Thanks for the post!

  • Guest

    Can you make a little Box2d tutorial like: “Skinning a body in box2d for dummies”?

    skinning-> “applying textures or assigning a movieclip to a rigid body in box2d” mini-tutorial
    not only to boxes (sprites) but to a main character (movieclip)

  • If you shoot down really fast, you can fly!

  • SO69

    Great tutorial, thanks!
    Can you show other basic elements in a box2d platform game, like: trampolines, bumps, ladders moving platforms and basic enemies? that would be great!

  • Guest

    Emanuele, do you think it’s possible to use this to create a “hook”? i mean, like batman, or spiderman,… you throw a rope/whip to the roof, then you can swing using it… do you think its possible with box2D?

  • I am creating a 2-player shooter game using this engine and I was stuck at how to assign different keys (I was able to get another person to show up) but this showed me how I can do this, by creating another class, thanks! But how would I get the turret part onto the second player? I was also having trouble assigning the mouse event shoot and charge to keys, any help? :D

  • Part 3 should include reloading times and a way to control two different heroes with different keybindings. Also, how would one change the bazooka angle from being controlled by the mouse to a standard platform shooter where is either facing left or right and you control that with your mouse keys? I also couldn’t find a way to shoot with a certain key on the keyboard -.-

  • Jodi Houareau

    Thanks awesome tutorial! Having some trouble with skinning it tho if you looking for more tutorial ideas!

  • Man, you are the best :P , these tutorials are just so perfect.
    I tried to watch the video tutorials from – and didn’t got anything from what he tried to explain :D , and these are the real thing! Thanks a lot.

  • shinboiz

    Hi, i’m beginner using box2d. And i wonder how to replace BoxShape bullet by CircleShape bullet. Can you help me about this. Thanks…

    P/s: and a small trouble : Did you use old version of box2D, cause when i use box2D new version for this project so it’s not working.

  • T_N_D

    Hello, great tutorial!!

    Why the player have some easeout when i stop moving? How i can remove it?


  • Tony

    ReferenceError: Error #1056: Cannot create property name on String.
    What should I do?