总的来说,我对 cocos2d 和 Objective-c 有点陌生,所以请多多包涵。我的代码中有一个 EXC_BAD_ACCESS 错误,所以我做了我通常做的事情,并打开了 NSZombies。这通常会吐出一些有用的东西,但这次什么也没吐出,程序也没有崩溃。
崩溃发生在我的敌人类中更新功能的第二行
- (void)update:(ccTime)delta{
speed = SPEED;
angleToTargetInRadians = -atan2((self.position.y-target.position.y),(self.position.x-target.position.x));
speed 和 angleToTargetInRadians 都是在头文件中定义的双精度值。
当第 4 个或第 5 个敌人被杀死时,就会发生崩溃。
- (void)die {
//give the player some points
[((AppController *)[UIApplication sharedApplication].delegate) addScore:POINTVALUE];
//make the shattered sprite
ShatteredSprite * blownUpShip = [ShatteredSprite shatterWithSprite:self piecesX:4 piecesY:4 speed:3 rotation:.02];
//add it to the layer
[self.parent addChild:blownUpShip];
//set the position and momentum and scale
[blownUpShip setVx: Vx];
[blownUpShip setVy: Vy];
[blownUpShip setScale:self.scale];
[blownUpShip setPosition:self.position];
[blownUpShip setRotation:self.rotation];
//get rid of the old ship
[self removeSelf];
}
- (void)removeSelf {
//remove self from array
NSMutableArray * enemies = [((AppController *)[UIApplication sharedApplication].delegate) Enemies];
[enemies removeObject:self];
[super die];
}
[超级死] 只是
[self removeFromParentAndCleanup:FALSE];
任何帮助表示赞赏!谢谢!