Cocos2d v3.0 + Box2d在创建体时崩溃了

时间:2014-02-28 11:52:22

标签: cocos2d-iphone box2d box2d-iphone

我从Cocos2d 2.0获取Box2d文件夹并将其添加到Cocos2d 3.0。 Box2d的初始化工作也得到了绿色边界框。一旦我创建了b2body,游戏就崩溃了。

请查找我的B2Body创建代码:

-(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);
}

这是坠毁时的屏幕截图。它总是崩溃..我可以修复吗?

enter image description here

«启用了ARC,我为所有box2d文件设置了-fno-objc-arc标志......但仍然崩溃。

1 个答案:

答案 0 :(得分:1)

-(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);
}