【问题标题】:How to stop runAction in cocos2d如何在 cocos2d 中停止 runAction
【发布时间】:2013-04-10 05:49:29
【问题描述】:

如何在一段时间后停止游戏中的所有动作?

在下面的代码中,我在精灵上调用 runaction。

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

在这段代码中,精灵不断移动。如何在一段时间或某种条件后停止上述动作?

【问题讨论】:

    标签: iphone ios cocos2d-iphone


    【解决方案1】:

    runAction call Functionstop action 中为sprite

    [CCCallFuncN actionWithTarget:self selector:@selector(setInvisible:)];
    
    - (void)setInvisiblestone:(CCNode *)node
    {
        [target stopAllActions];
    }
    

    【讨论】:

    • runaction 是每 1 秒后调用 periodacllay .. 甚至目标也不是单个对象。它不止一次。 runaction 从 -(void)addTraget:(ccTime)dt{ } 调用,addTraget 调用为 [self schedule:@selector(addTraget:) interval:1.5];那么如何停止这个动作呢?这是预定的
    • 你可以使用这个代码...[self unschedule:@selector(addTraget:)] or [self schedule:@selector(addTraget:) interval:1.5 repeat:NO delay:NO];
    【解决方案2】:

    方法中的所有动作都停止。

    -(void)gameover
    {
         [self unscheduleAllSelectors];
    }
    

    【讨论】:

    • 请在代码前使用4个空格将其格式化为代码。
    • 请详细说明这段代码是如何回答这个问题的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多