Actionscript:
-
import com.actionsnippet.qbox.*;
-
import Box2D.Common.Math.*;
-
import Box2D.Collision.Shapes.*;
-
-
[SWF(width = 600, height = 600, backgroundColor = 0x000000, frameRate=60)]
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
sim.setDefault({fillColor:0x990000, lineColor:0xFFCC00});
-
sim.createStageWalls();
-
-
var shapeTypes:Array = ["circle", "box", "poly"];
-
var pnts:Array = [-1, 0, -0.5, -1, 0.5, -1, 1, 0, 0,0.5, -1, 0];
-
var poly:Array=[];
-
for (var i:int = 0; i<20; i++){
-
var xp:Number = 3 + Math.random()*15;
-
var yp:Number = 3 + Math.random()*15;
-
var w:Number = 0.2 + Math.random() * 2;
-
var h:Number = 0.2 + Math.random() * 2;
-
var r:Number = 0.2 + Math.random();
-
var ang:Number = Math.random() * Math.PI * 2;
-
var index:Number = int(Math.random()*shapeTypes.length);
-
var s:Number = 0.3 + Math.random()*0.7;
-
for (var j:int = 0; j<pnts.length; j++){
-
poly[j] = pnts[j] * s;
-
}
-
sim.setDefault({fillColor:int(Math.random()*255) <<16, lineColor:0xFFCC00});
-
sim.create(shapeTypes[index], {x:xp, y:yp, width:w, height:h, angle:ang, radius:r, points:poly, wireframe:false})
-
}
-
-
sim.start();
-
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...
One Trackback
[...] 20. createメソッドによるオブジェクトの生成 – QuickBox2D create() Method [...]