QuickBox2D create() Method

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2. import Box2D.Common.Math.*;
  3. import Box2D.Collision.Shapes.*;
  4.  
  5. [SWF(width = 600, height = 600, backgroundColor = 0x000000, frameRate=60)]
  6.  
  7. var sim:QuickBox2D = new QuickBox2D(this);
  8.  
  9. sim.setDefault({fillColor:0x990000, lineColor:0xFFCC00});
  10. sim.createStageWalls();
  11.  
  12. var shapeTypes:Array = ["circle", "box", "poly"];
  13. var pnts:Array = [-1, 0, -0.5, -1, 0.5, -1, 1, 0, 0,0.5, -1, 0];
  14. var poly:Array=[];
  15. for (var i:int = 0; i<20; i++){
  16.     var xp:Number = 3 + Math.random()*15;
  17.     var yp:Number = 3 + Math.random()*15;
  18.     var w:Number = 0.2 + Math.random() * 2;
  19.     var h:Number = 0.2 + Math.random() * 2;
  20.     var r:Number = 0.2 + Math.random();
  21.     var ang:Number = Math.random() * Math.PI * 2;
  22.     var index:Number = int(Math.random()*shapeTypes.length);
  23.     var s:Number = 0.3 + Math.random()*0.7;
  24.     for (var j:int = 0; j<pnts.length; j++){
  25.          poly[j] = pnts[j] * s;
  26.     }
  27.     sim.setDefault({fillColor:int(Math.random()*255) <<16, lineColor:0xFFCC00});
  28.     sim.create(shapeTypes[index], {x:xp, y:yp, width:w, height:h, angle:ang, radius:r, points:poly, wireframe:false})
  29. }
  30.  
  31. sim.start();
  32. sim.mouseDrag();

Was showing someone QuickBox2D today and created this demo after showing them a few other posts. After writing this, I realized I hadn't posted about the QuickBox2D.create() method. Which is what addBox(), addRect(), addJoint() etc.. use internally. It takes a string for the type of QuickObject you'd like to create along with the standard params Object. Note that depending on the QuickObject type certain params will simply be ignored - for example radius is ignored when the type is "box" etc...


Have a look at the swf...

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

One Trackback

  1. [...] 20. createメソッドによるオブジェクトの生成 – QuickBox2D create() Method [...]

Post a Comment

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

*
*