私はcocos2dとobjective-c全般にちょっと慣れていないので、我慢してください。コードで EXC_BAD_ACCESS エラーが発生したため、通常どおりに実行し、NSZombies をオンにしました。これは通常、何か役に立つものを吐き出しますが、今回は何も吐き出さず、プログラムはクラッシュしませんでした。
クラッシュは、敵クラスの更新関数の 2 行目で発生します。
- (void)update:(ccTime)delta{
speed = SPEED;
angleToTargetInRadians = -atan2((self.position.y-target.position.y),(self.position.x-target.position.x));
speed と angleToTargetInRadians は両方とも、ヘッダー ファイルで定義された double です。
クラッシュは、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];
どんな助けでも大歓迎です!ありがとう!