我正在抛出一个对象(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;
}
答案 0 :(得分:0)
可能你正在丢失freeBodySprite
内存参考。
尝试将其创建为retain
属性,并始终在代码中使用self.freeBodySprite
。
@property (nonatomic, retain) CCSprite *freeBodySprite;
...
self.freeBodySprite = [CCSprite spriteWithFile:@"object.png"];
...
self.freeBodySprite.position.x;
答案 1 :(得分:0)
我有一个计时器,每0.01秒安排一次。我正在触摸端上制作freebody = nil,所以每当它为零且我的计时器方法运行时它就给了我这个错误。