【问题标题】:How to stop a scheduled runAction in cocos2d如何在 cocos2d 中停止预定的 runAction
【发布时间】:2013-04-10 09:22:32
【问题描述】:

我正在使用下面的代码添加精灵,这些精灵将在每 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 方法被调度了,那么在满足某个条件一段时间后如何停止这个调度的动作呢?

【问题讨论】:

  • 您使用以下代码进行日程安排。重复选项是否存在 [self schedule:@selector(addTraget:) interval:1.5 repeat:NO delay:NO];
  • 亲爱的,我想重复 1 分钟或在满足条件之前...我通过 [self unscheduleAllSelectors] 得到了解决方案;

标签: iphone ios cocos2d-iphone ccsprite


【解决方案1】:

只有取消调度特定的调度器然后使用这个:

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

【讨论】:

    【解决方案2】:
    [self unscheduleAllSelectors]; //For all selectors
    

    或者,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      相关资源
      最近更新 更多