creating Physic body in cocos2d

坚强是说给别人听的谎言 提交于 2019-12-08 09:09:17

问题


I am creating the physical body in box2d as below , this si my code

 b2BodyDef carBodyDef;
carBodyDef.position.Set(x/PTM_RATIO,y/PTM_RATIO);
carBodyDef.type=b2_dynamicBody;    b2Body* carBody=physicsWorld->CreateBody(&carBodyDef);

b2CircleShape carShape;
carShape.m_radius=rad/40.0f;


b2FixtureDef carFixture;
carFixture.shape=&carShape;
carFixture.density = 1.0f;
carFixture.friction = 0.0f;

carBody->CreateFixture(&carFixture);

return carBody ;

When am running the app, its getting crash , with the below erro *Assertion failed: (IsLocked() == false), function CreateBody,*in box2d


回答1:


That's because you are creating your body during execution of Step() function of b2World. You can't create new bodies while this function is executing



来源:https://stackoverflow.com/questions/9428367/creating-physic-body-in-cocos2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!