1
votes

I took Box2d folder from Cocos2d 2.0 and added it to Cocos2d 3.0. Initialization of Box2d worked and got green bounding box also. Game crashed as soon as I create b2body.

Please find my B2Body creation code:

-(void)createBody
{
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position.Set((self.position.x)/PTM_RATIO, (self.position.y)/PTM_RATIO);    
    bodyDef.userData = ((__bridge void*)self);

    b2PolygonShape box;
    box.SetAsBox( ((sW)/PTM_RATIO), ((sH)/PTM_RATIO));

    self.body = self.world->CreateBody(&bodyDef);
}

Here is screenshot when crashed. It always crash..how can I fix ?

enter image description here

« ARC enabled, I set -fno-objc-arc flag for all box2d files...but still crashed.

1
self.body = self.world->CreateBody(&bodyDef); after this u should write self.body->createFixture(&shape, 1);Singhak
@Singhak, please upload sample Cocos2d 3.0 and Box2d xcode project if you have. Thanks in advance.iPhoneProcessor

1 Answers

1
votes
-(void)createBody
{
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position.Set((self.position.x)/PTM_RATIO, (self.position.y)/PTM_RATIO);    
    bodyDef.userData = ((__bridge void*)self);

    b2PolygonShape box;
    box.SetAsBox( ((sW)/PTM_RATIO), ((sH)/PTM_RATIO));

    self.body = self.world->CreateBody(&bodyDef);
    self.body->createFixture(&box, 1);
}