Build 10 games and learn game development along the way in this fast paced game development course

Get the source code of 12 commercial games, loaded 50+ million times, and learn the secrets of game design

Learn how to make a successful Flash game from a real world example. Fully commented source code

Create realistic Flash physics games from scratch with advanced features, from Angry Birds to Crush the Castle

Add Box2D physics to your projects in a snap with PhysInjector

Do you want to add physics to your Flash projects with almost no code, keeping your scripts simple with only a few modifications, injecting physics attributes directly on your Display Ojects?

Then PhysInjector is the library you’ll love.

PhysInjector is a collection of powerfull factory and wrapper classes developed to work specifically with Box2D and does not do any collision detection on its own, rather it significantly simplifies the use of Box2D within your Flash games and applications while providing an array of handy plugins and helper classes.

PhysInjector takes a totally different approach than other conventional physics libraries. Instead of you having to create a physics object and apply a display object as a skin, it actually uses display objects that have already been added to the stage and “injects” them with physics properties. You don’t have to worry about the display object’s position, scale or rotation! PhysInjector will handle that for you!

I made a little example to let you see how easy is to ijnect physics into Display Objects.

The following script just adds black squares when you click the mouse, with no physics at all, it just places black squares on the screen.

Something like “my first AS3 script”:

And this is the result:

Click on the stage to add a black square.

Now, look at the same example, with physics injection: it’s very easy to understand:

And see what happens:

Click on the stage to add black squares which will turn into dynamic bodies.

Did you see how quick and easy it is? Download the source code with all needed libraries.

Next time I’ll show you how to code a complete physics game prototype just using a couple of lines (well, maybe a bit more, but you got the point).

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 5.00 out of 5)
Loading ... Loading ...
Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now
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. mmankt

    on March 27, 2013 at 9:14 pm

    lol i’ve been doing this since i started with box2d 3 years ago. no need for fancy-named libs, just a few lines of code.

  2. Arwin

    on March 27, 2013 at 9:53 pm

    Awesome. Could be very useful for mobile apps.

  3. HeroPunchTeam

    on March 27, 2013 at 10:15 pm

    Need to learn this fast. I’m sure this will be useful to our future projects.

  4. kek

    on March 28, 2013 at 9:48 am

    Why not use Quickbox2D ?

  5. benben

    on March 28, 2013 at 11:26 am

    How to remove the box when the box out of stage?

  6. foster

    on March 28, 2013 at 11:36 am

    @kek Qbox2D is dead bro :(

  7. reyco1

    on March 28, 2013 at 10:28 pm

    @benben to remove physics from any object just do


    physics.removePhysics( myObj );

    You can then remove your box manually with removeChild.

  8. benben

    on March 30, 2013 at 11:08 am

    @reyco1,
    In ContactTest.as,I want to remove the obj(bodyA),
    add the Code [physics.removePhysics(bodyA);],
    But can not remove bodyA.
    I’m not Sure If I need to remove the bodyA userData at first.

    The code as follow:

    private function handleContact(bodyA:b2Body, bodyB:b2Body, fixtureA:b2Fixture, fixtureB:b2Fixture):void{
    physics.removePhysics(bodyA);
    }

  9. reyco1

    on March 30, 2013 at 10:24 pm

    @benben all that does is remove the physics properties from the display object. Do removePhysics and then perform a removeChild.

  10. benben

    on April 1, 2013 at 3:54 am

    @reyco1,Thank you!
    I get it!

  11. Abdul

    on April 4, 2013 at 7:34 pm

    You should start your own youtube channel man. I’d watch your guides!

  12. benben

    on April 9, 2013 at 9:56 am

    @reyco1:
    If I set the box.rotation = 45;,And show the debug Draw.
    The displayObject can not at the position as the debug object.
    That is Why?

  13. faisal

    on April 13, 2013 at 11:55 am

    Can i add physics to irregular display objects ? rather than squares and circles etc. Also can we create terrain using this library ?

  14. steven yeung

    on June 12, 2013 at 2:35 pm

    I have a question, in box2d how do i add a shadow underneath the object so that it simulates / calculates it is falling from a great height

  15. Konstantin

    on June 22, 2013 at 7:14 am

    How to disable drag and drop?

  16. PhysInjector game prototype in only 100 lines of code - Emanuele Feronato

    on July 15, 2013 at 10:32 am

    […] days ago I showed you a new Box2D library called PhysInjector, now it’s time to let you see how can you make a fully working physics […]

  17. Starling + TexturePacker + PhysInjector + usaha = SERU! | DigitalCrawler

    on December 28, 2013 at 5:52 pm

    […] sebuah library yang menggunakan framework Box2d secara instan. Bahkan pakar actionscript seperti Emanuele Feronato menunjukkan penggunaan library ini dalam bentuk yang sangat […]

  18. akinori

    on March 12, 2014 at 7:54 pm

    Hi,
    thank you for providing so much infos and tutorials about box2d. I am testing PhysInjector and I do not find a way to manage a camera.
    Creating and adding all my objects in a specific sprite, when trying to move the sprite like a camera, all my objects still stay at the their same position as if all coordinates were calculated relative to the document stage.

    Is their a way to prevent this behavior and to move the PhysInjector’s stage ?

    Thank you for your help

Thank you for the download!!

I hope you will find it useful and make something interesting out of it

To keep up to date with the blog, why don't you like my Facebook page and follow me on Twitter?

Want to learn more? Don't miss this:

Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now

×