QuickBox2D

Downloads

(recommended version)
QuickBox2D 1.1

If you don't already know, Box2D is a great physics library created by Erin Catto. It was ported to AS3 by Matthew Bush and John Nesky. You can download the AS3 version of the library from the below link...

Go Get Box2DFlashAS3 2.0.2.

WARNING: QuickBox2D currently only works with Box2DFlashAS3 2.0.2 and earliear versions, so be sure to download 2.0.2 (2.1a is still quite alpha from what I can tell).

QuickBox2D is a mini-library I created to work with Box2DFlashAS3. The main purpose of this library is to significantly simplify instantiation of rigid bodies and provide a simple way to skin rigid bodies with custom graphics.

Additional features include:
Polygon Triangulation
FRIM (frame rate independent movement)

(old versions)
QuickBox2D 1.0
QuickBox2D alpha 108
QuickBox2D alpha 107
QuickBox2D alpha 106
QuickBox2D alpha 105

Documentation

You'll want to check out the QuickBox2D class and the QuickObject:
View the documentation

Examples

I've written a few posts that demo some of the features of QuickBox2D. Check them out here.

A tutorial is also in the works, but in the meantime once you've downloaded QuickBox2D and placed it in your classpath, you can try out some of these step by step snippets on your timeline...

Simple example, creates a box and a circle:

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2.  
  3. stage.frameRate = 60;
  4.  
  5. var sim:QuickBox2D = new QuickBox2D(this);
  6.  
  7. sim.createStageWalls();
  8.  
  9. sim.addBox({x:5, y:5, width:1, height:1});
  10. sim.addCircle({x:4, y:8, radius:2});
  11.  
  12. sim.start();
  13. sim.mouseDrag();

More accurate collision detection for fast moving objects:

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2.  
  3. stage.frameRate = 60;
  4.  
  5. var sim:QuickBox2D = new QuickBox2D(this);
  6.  
  7. sim.createStageWalls();
  8.  
  9. // turn on CCD for more accurate (and expensive) collision detection.
  10. sim.addBox({x:5, y:5, width:1, height:1, isBullet:true});
  11.  
  12. sim.addCircle({x:4, y:8, radius:2});
  13.  
  14. sim.start();
  15. sim.mouseDrag();

Easily change the color of rigid bodies:

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2.  
  3. stage.frameRate = 60;
  4.  
  5. var sim:QuickBox2D = new QuickBox2D(this);
  6.  
  7. sim.createStageWalls();
  8.  
  9. // use QuickBox2D's simple renderer to change the color of rigid bodies
  10. sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, fillColor:0xFFFF00});
  11.  
  12. sim.addCircle({x:4, y:8, radius:2, fillColor:0xCC0000, fillAlpha:.5, lineThickness:3, lineAlpha:.5});
  13.  
  14. sim.start();
  15. sim.mouseDrag();

The setDefault() method allows global changes to the default params argument:

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2.  
  3. stage.frameRate = 60;
  4.  
  5. var sim:QuickBox2D = new QuickBox2D(this);
  6.  
  7. // we can set default properties for all QuickObjects (now all objects will be green with no stroke)
  8. sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
  9.  
  10. sim.createStageWalls();
  11.  
  12. sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
  13.  
  14. sim.addCircle({x:4, y:8, radius:2});
  15.  
  16. // will use the new default radius of 1.5
  17. sim.addCircle({x:10, y:4, fillColor:0x666666});
  18.  
  19. sim.start();
  20. sim.mouseDrag();

Static bodies (bodies that don't move) are created by setting density to 0:

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2.  
  3. stage.frameRate = 60;
  4.  
  5. var sim:QuickBox2D = new QuickBox2D(this);
  6.  
  7. // we can set default properties for all QuickObjects
  8. sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
  9.  
  10. sim.createStageWalls();
  11.  
  12. sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
  13.  
  14. sim.addCircle({x:4, y:8, radius:2});
  15.  
  16. // will use the new default radius of 1.5
  17. sim.addCircle({x:10, y:4, fillColor:0x666666});
  18.  
  19. // creating static bodies is done by setting density to 0
  20. sim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});
  21.  
  22. sim.start();
  23. sim.mouseDrag();

Creating polygons:

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2.  
  3. stage.frameRate = 60;
  4.  
  5. var sim:QuickBox2D = new QuickBox2D(this);
  6.  
  7. // we can set default properties for all QuickObjects
  8. sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
  9.  
  10. sim.createStageWalls();
  11.  
  12. sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
  13.  
  14. sim.addCircle({x:4, y:8, radius:2});
  15.  
  16. // will use the new default radius of 1.5
  17. sim.addCircle({x:10, y:4, fillColor:0x666666});
  18.  
  19. // creating static bodies is done by setting density to 0
  20. sim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});
  21.  
  22. // polygon vertices must be defined from top to bottom and clockwise
  23. sim.addPoly({x:15, y:8, verts:[[0,0,2,2,0,2]], fillColor:0x0000FF});
  24.  
  25. sim.start();
  26. sim.mouseDrag();

Creating complex polygons:

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2.  
  3. stage.frameRate = 60;
  4.  
  5. var sim:QuickBox2D = new QuickBox2D(this);
  6.  
  7. // we can set default properties for all QuickObjects
  8. sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
  9.  
  10. sim.createStageWalls();
  11.  
  12. sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
  13.  
  14. sim.addCircle({x:4, y:8, radius:2});
  15.  
  16. // will use the new default radius of 1.5
  17. sim.addCircle({x:10, y:4, fillColor:0x666666});
  18.  
  19. // creating static bodies is done by setting density to 0
  20. sim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});
  21.  
  22. // polygon vertices must be defined from top to bottom and clockwise
  23. // additional polygons can be added in the form of arrays. Each individual
  24. // poly must be convex and can only have up to 8 vertices
  25. // there is no limit to the number of polygons you can add - and combined polygons
  26. // can be used to create concave shapes
  27. sim.addPoly({x:15, y:8, verts:[[0,0,2,2,0,2], [0,0,0,1,-2,-0.2]], fillColor:0x0000FF});
  28.  
  29. sim.start();
  30. sim.mouseDrag();

Using debug draw mode:

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2.  
  3. stage.frameRate = 60;
  4.  
  5. // QuickBox2D can optionally take parameters for the world and rendering
  6. // by setting debug to true we can use the Box2D debug renderer
  7. var sim:QuickBox2D = new QuickBox2D(this, {debug:true});
  8.  
  9. // we can set default properties for all QuickObjects
  10. sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
  11.  
  12. sim.createStageWalls();
  13.  
  14. sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
  15.  
  16. sim.addCircle({x:4, y:8, radius:2});
  17.  
  18. // will use the new default radius of 1.5
  19. sim.addCircle({x:10, y:4, fillColor:0x666666});
  20.  
  21. // creating static bodies is done by setting density to 0
  22. sim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});
  23.  
  24. // polygon vertices must be defined from top to bottom and clockwise
  25. // additional polygons can be added in the form of arrays. Each individual
  26. // poly must be convex and can only have up to 8 vertices
  27. // there is no limit to the number of polygons you can add - and combined polygons
  28. // can be used to create convex shapes
  29. sim.addPoly({x:15, y:8, verts:[[0,0,2,2,0,2], [0,0,0,1,-2,-0.2]], fillColor:0x0000FF});
  30.  
  31. sim.start();
  32. sim.mouseDrag();