0

我正在抛出一个对象(box2d),但是当我尝试进行碰撞检测时,它在该对象的 CGRect 上给了我错误。见下图

在此处输入图像描述

这就是我创建对象主体的方式

-(void) createObject
{
    freeBodySprite = [CCSprite spriteWithFile:@"object.png"];
    //freeBodySprite.position = ccp(100, 300);
    [self addChild:freeBodySprite z:2 tag:6];

    CGPoint startPos = CGPointMake(150, 320/1.25);

    bodyDef.type = b2_staticBody;
    bodyDef.position = [self toMeters:startPos];
    bodyDef.userData = freeBodySprite;


    float radiusInMeters = ((freeBodySprite.contentSize.width * freeBodySprite.scale/PTM_RATIO) * 0.5f);
    shape.m_radius = radiusInMeters;


    fixtureDef.shape = &shape;
    fixtureDef.density = 0.02f;
    fixtureDef.friction = 1.0f;
    fixtureDef.restitution = 0.0f;

    circularObstacleBody = world->CreateBody(&bodyDef);
    stoneFixture = circularObstacleBody->CreateFixture(&fixtureDef);
    freeBody = circularObstacleBody;

}
4

2 回答 2

0

我有一个计时器,每 0.01 秒安排一次。我在触摸端制作 freebody = nil 所以每当它是 nil 并且我的计时器方法正在运行时,它都会给我这个错误。

于 2013-06-17T09:59:11.370 回答
0

可能您正在丢失freeBodySprite内存参考。

尝试将其创建为retain属性,并始终self.freeBodySprite在您的代码中使用。

@property (nonatomic, retain) CCSprite *freeBodySprite;

...

self.freeBodySprite = [CCSprite spriteWithFile:@"object.png"];

... 

self.freeBodySprite.position.x;
于 2013-06-13T18:22:22.307 回答