-1
-(void)spriteMoveFinishedid)sender    //when sprite is outside of screen,it's deleted;
{
     CCSprite *sprite = (CCSprite *)sender;
     if (sprite.tag == 1)    //it's enemy;
    {  
        escapeNum++;
       [self removeChild:sprite cleanup:YES];
        if (escapeNum == 10) 
        {
            [self stopGameEx];   //Because the speed of every enemy isn't same to other and there are bullets,it maybe happens that two sprites disappear at the same time, and the program stop at this with error --- program received signal:“EXC_BAD_ACCESS”。
        }
      //...........
    }
}

それを解決する方法は?

4

1 に答える 1

0

if ループ内で、スプライト タグを変更して期限切れのスプライトとしてマークし、その他の場所を削除します。

enum
{
   kTagExpiredSprite = 999 //any number not ur sprite tag(1)
};

.....

-(void)spriteMoveFinishedid)sender    //when sprite is outside of screen,it's deleted;
{
     CCSprite *sprite = (CCSprite *)sender;
     if (sprite.tag == 1)    //it's enemy;
    {  
        escapeNum++;
       sprite.tag = kTagExpiredSprite;
        if (escapeNum == 10) 
        {
            [self stopGameEx];   //Because the speed of every enemy isn't same to other and there are bullets,it maybe happens that two sprites disappear at the same time, and the program stop at this with error --- program received signal:“EXC_BAD_ACCESS”。
        }
      //...........
    }
}
于 2012-07-10T14:06:03.497 に答える