我试图用鼠标捕捉对象。因为我是个傻瓜,所以偷了密码。但不管是我还是我都没用。
我发现了这个错误:
Uncaught : Object #< ba >没有方法'IsActive‘Box2dWeb-2.1.a.3.min.js:236 Uncaught : Object #< ba >没有方法'SetAwake’Box2dWeb2.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;}
也许有人能帮忙?
福克
发布于 2014-02-16 22:05:28
我可以回答一半的问题:
如果我用
ground = createBox(world, 4, 1, 4 , 0.5, {type : b2Body.b2_staticBody});与此函数相反: var bodyDef =新的b2BodyDef();
var fixDef = new b2FixtureDef();
fixDef.density = 1.0;
fixDef.friction = 1.0;
fixDef.restitution = 0.5;
fixDef.shape = new b2PolygonShape;
//mention half the sizes
fixDef.shape.SetAsBox(4.00 , .5);
//set the position of the center
bodyDef.position.Set(4.10 , 1);
return world.CreateBody(bodyDef).CreateFixture(fixDef);那它就起作用了。但是为什么呢?
https://stackoverflow.com/questions/21816402
复制相似问题