obj-cには比較的新しいので、何かが欠落しているはずですが、敵が壁に衝突するとプログラムがクラッシュします。私はループの中で敵を取り除いているところに位置していましたが、私の人生では、どうやって修正するのか分かりません。 私のコードは以下の通りである:コレクション<__ NSArrayM:0x76c11b0>は列挙中に突然変異しました
は(エラーがある "[allEnemies REMOVEOBJECT:enemyType1];")
//常に実行 - (ボイド)更新:(ccTime)DT {
for (CCSprite *enemyType1 in allEnemies) { //for every attacking unit in allEnemies
//Adjust the collison box for each enemey depending on the height of the enemy
float a;
float b;
float yOne = (wall.contentSize.height-enemyType1.position.y);
float yTwo = (wall.contentSize.height);
float xTwo = 30;
a = (xTwo*(yOne/yTwo)); // always < 1
b = xTwo-a; // always > 1
//Create the altered collison box
CGRect enemyType1Rect = CGRectMake (
enemyType1.position.x - (enemyType1.contentSize.width/2),
enemyType1.position.y - (enemyType1.contentSize.height/2),
enemyType1.contentSize.width+b,
enemyType1.contentSize.height
);
//If the enemey hits the wall, stop it, then add it to the attacking enemies array
if (CGRectIntersectsRect(enemyType1Rect, wall.boundingBox)) {
[enemyType1 stopAllActions];
[allEnemies removeObject:enemyType1];
[attackingEnemies addObject:enemyType1];
}
}
//Wall Collison END
OK、あなたはそれがまったく同じものを説明することができ。 [allEnemies copy]は配列のコピーを作成しますが、それを元の "allEnemies"配列から削除します。また、そこに「autorelease」を置くと、「[allEnemies removeObject:enemyType1];」を持つ必要はありません。右?申し訳ありませんが、これは本当にダム(私はちょうどxcode 4を持っていて、これは私の3を悩ませていない)。 編集: そのコードを変更したところ、次のようになりました。 com.yourcompany.StromTheHouseをブートストラップサーバーに登録できませんでした。エラー:不明なエラーコード。 – user1091516
xcodeは私を嫌っています。だから、私は([allEnemies copy autorelease]のCCSprite * enemyType1)を取得すると思いますが、ブートストラップエラーは表示されませんが、今Deviceでテストしようとすると新しいエラーが発生します: StormTheHouse [11129:707] cocos2d:画像を追加できませんでした:壁。CCTextureCacheのpng 2011-12-10 11:02:05.888 StormTheHouse [11129:707] ***アサーションエラー - [HelloWorld addChild:]、/Users/rauhul/Desktop/Invasion/libs/cocos2d/CCNode.m: 385 2011-12-10 11:02:05.890 StormTheHouse [11129:707]キャッチされていない例外 'NSInternalInconsistencyException'のためアプリを終了しています、理由: '引数は非nilでなければなりません' – user1091516
nvmこれらの投稿私はコード内でwall.pngを参照していましたが、イメージはWALL.png、Thx soooo much – user1091516