function createBox(x:Number, y:Number, w:Number, h:Number, angle:Number, isDynamic:Boolean):b2Body;
function createCircle(x:Number, y:Number, r:Number, isDynamic:Boolean):b2Body;
function onClick(event:MouseEvent):void {
createCircle(mouseX, mouseY, Math.random()*20+15, true);
}
function createPrismaticJoint(body1:b2Body, body2:b2Body, anchor:b2Vec2, axis:b2Vec2, thick:Number):void
{
var jointDef:b2PrismaticJointDef = new b2PrismaticJointDef();
jointDef.Initialize(body1, body2, anchor, axis);
jointDef.collideConnected = false;
jointDef.enableLimit = true;
jointDef.enableMotor = true;
jointDef.lowerTranslation = -(thick/2)/scale;
jointDef.upperTranslation = (thick/2)/scale;
jointDef.motorSpeed = 3;
jointDef.maxMotorForce = 2900;
world.CreateJoint(jointDef);
}
function createSpring(px:Number, py:Number, w:Number, h:Number):void
{
var b1:b2Body = createBox(px, py-h/2, 5, h, 0, false);
var b2:b2Body = createBox(px, py-h, w, h-10, 0, true);
var anchor:b2Vec2 = new b2Vec2(px/scale,py/scale);
var axis:b2Vec2 = new b2Vec2(0,-1);
createPrismaticJoint(b1,b2,anchor,axis,h-10);
}
for (var i:int = 0 ; i < 10 ; i++) {
createSpring(25+50*i, 400, 48, 30);
}
'programming > box2d docs' 카테고리의 다른 글
b2PulleyJoint 예제 (0) | 2011.02.01 |
---|---|
b2Revolute Joint 예제 (0) | 2011.01.30 |
b2DistanceJoint 예제 (0) | 2011.01.28 |
b2Body 예제 - Box2DFlash (4) | 2011.01.17 |
Box2DFlash v2.1a Update Notes 비공식 한글문서 (0) | 2011.01.16 |
WRITTEN BY