How to stop the targets generated by schedule:@selector(target:) interval:timeInterval ?

Posted by srikanth rongali on Stack Overflow See other posts from Stack Overflow or by srikanth rongali
Published on 2010-04-09T04:16:24Z Indexed on 2010/04/09 4:23 UTC
Read the original article Hit count: 327

Filed under:
|

I am using
[self schedule:@selector(target:) interval:timeInterval];
for generating bullets in shooting game in cocos2d. In target: I called method targetGenerate to generate for bullet. The enemy generates these bullets. After the player won or enemy won the game the bullets should stop. But, I could not make them stop. I used flags for this. But they did either work.
If I set flag1 = 1; for game won.
I am using [self schedule:@selector(update:)]; for updating the bullet position to know it hits the player or not ? And I tried like this

-(id)init
{
   if( (self = [super init]) )
   {
     //code for enemy
     [self schedule:@selector(target:) interval:timeInterval]; 
     [self schedule:@selector(update:)];
   }return self;
}
-(void)target:(ccTime)dt
{
if(flag != 1)
[self targetGenerate];
} 

-(void)targetGenerate
{
//code for the bullet to generate;
CCSprite *bullet = …
}
-(void)update:(ccTime)dt
{
//code for to know intersection of bullet and player
}

But it was not working. How can I make the bullets to disappear after player won the game or enemy won the game ?
Thank you.

© Stack Overflow or respective owner

Related posts about cocos2d-iphone

Related posts about cocoa-touch