1
我想用鼠標使用mousejoint捕捉對象。由於我是個傻瓜,我偷了代碼。但它不工作或我。mouseJoint box2dweb不工作
我收到此錯誤:
Uncaught TypeError: Object #< ba > has no method 'IsActive' Box2dWeb-2.1.a.3.min.js:236 Uncaught TypeError: Object #< ba > has no method 'SetAwake' Box2dWeb-2.1.a.3.min.js:223
這裏是代碼:
var def = new b2MouseJointDef();
def.bodyA = ground;
def.bodyB = body;
def.target = p;
def.collideConnected = true;
def.maxForce = 1000 * body.GetMass();
def.dampingRatio = 0;
mouse_joint = world.CreateJoint(def);
body.SetAwake(true);
這是身體
function createBox(world, x, y, width, height, options) {
options = $.extend(true, {
'density' : 1.0 ,
'friction' : 1.0 ,
'restitution' : 0.5 ,
'linearDamping' : 0.0 ,
'angularDamping' : 0.0 ,
'type' : b2Body.b2_dynamicBody
}, options);
var body_def = new b2BodyDef();
var fix_def = new b2FixtureDef();
fix_def.density = options.density;
fix_def.friction = options.friction;
fix_def.restitution = options.restitution;
fix_def.shape = new b2PolygonShape();
fix_def.shape.SetAsBox(width , height);
body_def.position.Set(x , y);
body_def.linearDamping = options.linearDamping;
body_def.angularDamping = options.angularDamping;
body_def.type = options.type;
body_def.userData = options.user_data;
var b = world.CreateBody(body_def);
var f = b.CreateFixture(fix_def);
return b;
}
也許有人可以幫?
福爾克