Search code examples
iphoneioscocos2d-iphoneccsprite

How to stop a scheduled runAction in cocos2d


I am using below code to add sprites which will be created after every 1.5 seconds as follows

[self schedule:@selector(addTraget:) interval:1.5];

-(void)addTraget:(ccTime)dt{
CCSprite *target = [CCSprite spriteWithFile:@"img1.png" rect:CGRectMake(0, 0, 80, 36)];

target.position = ccp(-target.contentSize.width/2, 100);
[self addChild:target];
target.tag = 1;

id actionMove = [CCMoveTo actionWithDuration:actualDuration*2.5 position:ccp(winSize.width + (target.contentSize.width/2), actualY)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
id sequece = [CCSequence actions:delayTime1, calFun1, delayTime2, calFun2,actionMove, actionMoveDone, nil];
id repeate = [CCRepeatForever actionWithAction:sequece];

[target runAction:repeate];
}

as the addTarget method is scheduled then how to stop this scheduled action after some time of after satisfying a condition?


Solution

  • Only unschedule particular scheduler then use this:

    [self unschedule:@selector(addTraget:)];