Sammlung <__NSArrayM: 0x76c11b0> war, mutierte während aufgezählt werden

Ich bin relativ neu in obj-c, also ich muss etwas fehlen, aber mein Programm Abstürzen, wenn ein Feind, kollidiert mit einer Wand. Habe ich gelegen, wo ich bin, entfernen Sie den Feind aus der Schleife, während die Schleife, aber für das Leben von mir, ich kann nicht herausfinden, wie es zu lösen ist.
Mein code ist wie folgt:

(der Fehler ist "[allEnemies removeObject:enemyType1];")

//IMMER AUSGEFÜHRT
-(void) update:(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
InformationsquelleAutor user1091516 | 2011-12-10
Schreibe einen Kommentar