使用cocos2d来设计shootgame,我无法调用stopGame方法

时间:2012-06-28 03:07:02

标签: objective-c cocos2d-iphone

-(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”。
        }
      //...........
    }
}

如何解决?

1 个答案:

答案 0 :(得分: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”。
        }
      //...........
    }
}