我尝试设置一个棱柱形关节,但是我在运行时遇到了这个错误: 断言失败:(IsLocked()== false),函数CreateBody,文件/Users/Aether/Developer/JFRecode/JFRecode/libs/Box2D/Dynamics/b2World.cpp,第109行。
以下是屏幕边界的代码,因为我将它用作bodyB。
CGSize s = [CCDirector sharedDirector].winSize;
//define screen boundaries
// Create edges around the entire screen
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0,0);
_groundBody = _world->CreateBody(&groundBodyDef);
b2EdgeShape groundBox;
b2FixtureDef groundBoxDef;
groundBoxDef.shape = &groundBox;
groundBox.Set(b2Vec2(0,0), b2Vec2(s.width/PTM_RATIO, 0));
_bottomFixture = _groundBody->CreateFixture(&groundBoxDef);
groundBox.Set(b2Vec2(0,0), b2Vec2(0, s.height/PTM_RATIO));
_groundBody->CreateFixture(&groundBoxDef);
groundBox.Set(b2Vec2(0, s.height/PTM_RATIO), b2Vec2(s.width/PTM_RATIO,
s.height/PTM_RATIO));
_groundBody->CreateFixture(&groundBoxDef);
groundBox.Set(b2Vec2(s.width/PTM_RATIO, s.height/PTM_RATIO),
b2Vec2(s.width/PTM_RATIO, 0));
_groundBody->CreateFixture(&groundBoxDef);
以下是棱柱关节本身的代码
b2PrismaticJointDef jointDef;
b2Vec2 worldAxis(1.0f,0.0f);
jointDef.collideConnected = true;
jointDef.Initialize(_shipBody,_groundBody,
_shipBody->GetWorldCenter(), worldAxis);
_world->CreateJoint(&jointDef);
答案 0 :(得分:0)
isLocked表示物理世界正在更新。这意味着您在世界步骤方法期间运行此代码,可能是在联系回调方法中或由于联系回调方法。延迟执行此代码直到世界步骤之后。