如何在cocos2d中停止计划的runAction

时间:2013-04-10 09:22:33

标签: iphone ios cocos2d-iphone ccsprite

我正在使用下面的代码添加精灵,这些精灵将在每1.5秒之后创建,如下所示

[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];
}

作为addTarget方法的安排然后如何在满足条件后的一段时间后停止此计划的操作?

2 个答案:

答案 0 :(得分:4)

[self unscheduleAllSelectors]; //For all selectors

,或者

[self unschedule:@selector(YOURSELECTOR)]; //For specific selector

答案 1 :(得分:4)

只有取消安排特定的调度程序才能使用它:

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