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...
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:
-
import com.actionsnippet.qbox.*;
-
-
stage.frameRate = 60;
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
sim.createStageWalls();
-
-
sim.addBox({x:5, y:5, width:1, height:1});
-
sim.addCircle({x:4, y:8, radius:2});
-
-
sim.start();
-
sim.mouseDrag();
More accurate collision detection for fast moving objects:
-
import com.actionsnippet.qbox.*;
-
-
stage.frameRate = 60;
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
sim.createStageWalls();
-
-
// turn on CCD for more accurate (and expensive) collision detection.
-
sim.addBox({x:5, y:5, width:1, height:1, isBullet:true});
-
-
sim.addCircle({x:4, y:8, radius:2});
-
-
sim.start();
-
sim.mouseDrag();
Easily change the color of rigid bodies:
-
import com.actionsnippet.qbox.*;
-
-
stage.frameRate = 60;
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
sim.createStageWalls();
-
-
// use QuickBox2D's simple renderer to change the color of rigid bodies
-
sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, fillColor:0xFFFF00});
-
-
sim.addCircle({x:4, y:8, radius:2, fillColor:0xCC0000, fillAlpha:.5, lineThickness:3, lineAlpha:.5});
-
-
sim.start();
-
sim.mouseDrag();
The setDefault() method allows global changes to the default params argument:
-
import com.actionsnippet.qbox.*;
-
-
stage.frameRate = 60;
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
// we can set default properties for all QuickObjects (now all objects will be green with no stroke)
-
sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
-
-
sim.createStageWalls();
-
-
sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
-
-
sim.addCircle({x:4, y:8, radius:2});
-
-
// will use the new default radius of 1.5
-
sim.addCircle({x:10, y:4, fillColor:0x666666});
-
-
sim.start();
-
sim.mouseDrag();
Static bodies (bodies that don't move) are created by setting density to 0:
-
import com.actionsnippet.qbox.*;
-
-
stage.frameRate = 60;
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
// we can set default properties for all QuickObjects
-
sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
-
-
sim.createStageWalls();
-
-
sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
-
-
sim.addCircle({x:4, y:8, radius:2});
-
-
// will use the new default radius of 1.5
-
sim.addCircle({x:10, y:4, fillColor:0x666666});
-
-
// creating static bodies is done by setting density to 0
-
sim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});
-
-
sim.start();
-
sim.mouseDrag();
Creating polygons:
-
import com.actionsnippet.qbox.*;
-
-
stage.frameRate = 60;
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
// we can set default properties for all QuickObjects
-
sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
-
-
sim.createStageWalls();
-
-
sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
-
-
sim.addCircle({x:4, y:8, radius:2});
-
-
// will use the new default radius of 1.5
-
sim.addCircle({x:10, y:4, fillColor:0x666666});
-
-
// creating static bodies is done by setting density to 0
-
sim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});
-
-
// polygon vertices must be defined from top to bottom and clockwise
-
sim.addPoly({x:15, y:8, verts:[[0,0,2,2,0,2]], fillColor:0x0000FF});
-
-
sim.start();
-
sim.mouseDrag();
Creating complex polygons:
-
import com.actionsnippet.qbox.*;
-
-
stage.frameRate = 60;
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
// we can set default properties for all QuickObjects
-
sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
-
-
sim.createStageWalls();
-
-
sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
-
-
sim.addCircle({x:4, y:8, radius:2});
-
-
// will use the new default radius of 1.5
-
sim.addCircle({x:10, y:4, fillColor:0x666666});
-
-
// creating static bodies is done by setting density to 0
-
sim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});
-
-
// polygon vertices must be defined from top to bottom and clockwise
-
// additional polygons can be added in the form of arrays. Each individual
-
// poly must be convex and can only have up to 8 vertices
-
// there is no limit to the number of polygons you can add - and combined polygons
-
// can be used to create concave shapes
-
sim.addPoly({x:15, y:8, verts:[[0,0,2,2,0,2], [0,0,0,1,-2,-0.2]], fillColor:0x0000FF});
-
-
sim.start();
-
sim.mouseDrag();
Using debug draw mode:
-
import com.actionsnippet.qbox.*;
-
-
stage.frameRate = 60;
-
-
// QuickBox2D can optionally take parameters for the world and rendering
-
// by setting debug to true we can use the Box2D debug renderer
-
var sim:QuickBox2D = new QuickBox2D(this, {debug:true});
-
-
// we can set default properties for all QuickObjects
-
sim.setDefault({fillColor:0x00CC22, lineAlpha:0, radius:1.5});
-
-
sim.createStageWalls();
-
-
sim.addBox({x:5, y:5, width:1, height:1, lineColor:0xFF0000, lineAlpha:1});
-
-
sim.addCircle({x:4, y:8, radius:2});
-
-
// will use the new default radius of 1.5
-
sim.addCircle({x:10, y:4, fillColor:0x666666});
-
-
// creating static bodies is done by setting density to 0
-
sim.addBox({x:5, y:16, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000});
-
-
// polygon vertices must be defined from top to bottom and clockwise
-
// additional polygons can be added in the form of arrays. Each individual
-
// poly must be convex and can only have up to 8 vertices
-
// there is no limit to the number of polygons you can add - and combined polygons
-
// can be used to create convex shapes
-
sim.addPoly({x:15, y:8, verts:[[0,0,2,2,0,2], [0,0,0,1,-2,-0.2]], fillColor:0x0000FF});
-
-
sim.start();
-
sim.mouseDrag();