我正在尝试创建一个MouseJoint对象但由于某种原因Box2D在b2World上调用CreateJoint时发生了炸弹。我是box2d的新手,我无法确定我在这里做错了什么。我正在使用Cocos2d并启用了触控功能。在ccTouchesBegan委托方法中,我正在测试用户是否触及了感兴趣的主体; “桨”。
在构建b2MouseJointDef对象之后,此行会导致异常:
_mouseJoint =(b2MouseJoint *)_ world-> CreateJoint(& md);
World对象似乎在试图创建连接时爆炸。这里整个触及全部回调。任何想法??
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (_mouseJoint != NULL) return;
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
if (_paddleFixture->TestPoint(locationWorld)) {
b2MouseJointDef md;
md.bodyA = _groundBody;
md.bodyB = _paddleBody;
md.target = locationWorld;
md.collideConnected = true;
md.maxForce = 1000.0f * _paddleBody->GetMass();
_mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md);
_paddleBody->SetAwake(true);
}
}