function onClick(event:MouseEvent):void {
createBox(mouseX, mouseY, 30, 30, 0, true);
}
function createBox(px:Number, py:Number, w:Number, h:Number, angle:Number, isDynamic:Boolean):b2Body;
function createCircle(px:Number, py:Number, r:Number, isDynamic:Boolean):b2Body;
function createRevoluteJoint(body1:b2Body, body2:b2Body, anchor:b2Vec2):void
{
var jointDef:b2RevoluteJointDef = new b2RevoluteJointDef();
jointDef.Initialize(body1, body2, anchor);
jointDef.collideConnected = true;
jointDef.enableLimit = false;
jointDef.enableMotor = false;
world.CreateJoint(jointDef);
}
function createScale(px:Number, py:Number, w:Number, h:Number):b2Body
{
var center:b2Body = createCircle(px, py, 5, true);
var flate:b2Body = createBox(px, py+h, w, 10, 0, true);
createRevoluteJoint(flate, center, new b2Vec2((px-w/2)/scale, (py+h)/scale));
createRevoluteJoint(flate, center, new b2Vec2((px+w/2)/scale, (py+h)/scale));
return center;
}
function createPulleyJoint(body1:b2Body, body2:b2Body, ground1:b2Vec2, ground2:b2Vec2, anchor1:b2Vec2, anchor2:b2Vec2):void
{
var jointDef:b2PulleyJointDef = new b2PulleyJointDef();
jointDef.Initialize(body1, body2, ground1, ground2, anchor1, anchor2, 1);
jointDef.collideConnected = true;
jointDef.maxLengthA = 190;
jointDef.maxLengthB = 190;
world.CreateJoint(jointDef);
}
var ground1:b2Body = createCircle(100, 0, 5, false);
var ground2:b2Body = createCircle(400, 0, 5, false);
var scale1:b2Body = createScale(100, 200, 140, 90);
var scale2:b2Body = createScale(400, 200, 140, 90);
createPulleyJoint(scale1, scale2, ground1.GetWorldCenter(), ground2.GetWorldCenter(), scale1.GetWorldCenter(), scale2.GetWorldCenter());
'programming > box2d docs' 카테고리의 다른 글
b2PrismaticJoint 예제 (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