QuickBox2D Chain

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2.  
  3. var sim:QuickBox2D = new QuickBox2D(this, {debug:true});
  4. // use the box2D default renderer (debug : true)
  5.  
  6. sim.createStageWalls();
  7.  
  8. // anchor
  9. var pre:QuickObject = sim.addCircle({x:9, y:3, radius:.5, density:0});
  10.  
  11. // create a chain of boxes
  12. for (var i:int = 0; i<12; i++){
  13.   var curr:QuickObject = sim.addBox({x:10 + i, y:3, width:.9, height:.9, angularDamping:1});
  14.                                                                  
  15.   // currently always adds a b2DistanceJoint
  16.   sim.addJoint({a:pre.body, b:curr.body,
  17.                            x1:9 + i, y1: 3, x2: 10 + i, y2:3, collideConnected:false});
  18.   pre = curr;
  19. }
  20.  
  21. // add a circle, use CCD (isBullet)
  22. sim.addCircle({x:20, y:10, radius:1, isBullet:true});
  23.  
  24. // start simulation
  25. sim.start();
  26. sim.mouseDrag();

This snippet uses my QuickBox2D library to create a chain. QuickBox2D is a wrapper for Box2DFlashAS3 that greatly simplifies world setup, instantiation and graphical skinning of rigid bodies (more info on yesterdays post)...

See the swf here.

Download Box2DFlashAS3 here

Download QuickBox2D Alpha 104 here

See yesterdays post for additional information. I'm still in the process of writing some docs and possibly a tutorial for QuickBox2D... hopefully I'll finish with that soon...

If your somewhat familiar with Box2D and just want to just dig right in, the following scrap of information may help:


// Methods of the QuickBox2D class, used for creating rigid bodies and joints
addCircle();
addBox();
addPoly();
// currently only creates b2DistanceJoints
addJoint();

these function all take one parameter Object as their argument. The common parameter properties for rigid bodies are:

// QuickBox2D simpleRender settings:
lineColor:0x000000
lineAlpha:1
lineThickness:0
fillColor:0xCCCCCC
fillAlpha:1
// wrapped Box2D properties
x:3
y:3
density:1
friction:0.5
restitution:0.2
angle: 0
linearDamping:0
angularDamping:0
isBullet:false,
fixedRotation:false
allowSleep: true
isSleeping:false
// advanced use
maskBits:0xFFFF
categoryBits:1
groupIndex:0

//and the specific param properties are:
addCircle() : radius
addBox() : width, height
addPoly() : verts

//Joints have the following properties... not going to bother explaining these until I write the docs:
addJoint() : a, b, x1, x2, y1, y2

This entry was posted in Box2D, QuickBox2D, motion and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. brooklyn
    Posted March 25, 2010 at 6:04 am | Permalink

    when I run the sample code, it displays the boxes, but there is no simulation,

  2. brooklyn
    Posted March 25, 2010 at 6:11 am | Permalink

    actually, figured it out. By mistake, I managed to set the framerate as 0.01 :) setting it to 30 fixed the problem.

    QuickBox2D is a nice library. I liked your coding style.

2 Trackbacks

  1. [...] (4) 四角形のオブジェクトを作る。Box2DFlashAS3でなにか作るには、まず形状の定義をして、それから実体化する手順がいるけどQuickBox2DではこれひとつでOK。パラメータとしていろんな値を渡せるけど、ひとまず幅1m、高さ1mの四角形をx座標5m、y座標5mの地点に置いてます。 [...]

  2. [...] QuickBox2D Chain「addJointによるジョイントの生成」 [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*