-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 循环中,更改 sprite 标签以将其标记为过期的 sprite,并在其他地方删除。

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 回答