等待方法运行直到CCActionSequence结束

时间:2014-07-25 05:31:47

标签: objective-c cocos2d-iphone

-(void) gameplay
{
    if (actionhappen){
        CCActionSequence *mySeq = [CCActionSequence actionWithArray:@[do,some,action]];
        [mySprite runAction:mySeq]; // it takes 3 seconds.
    }
    [self checkWinner];
}


-(void)checkWinner{
if (someoneWin){
    // I want to wait here until mySeq action finished
        [self showWinnerMessage];
    }
}

在此代码中

[self showWinnerMessage]在mySeq结束之前运行。

我怎么能等到mySprite动作结束?

睡眠()似乎让一切都睡了。

1 个答案:

答案 0 :(得分:1)

嗯,@ LearnCocos2D已在评论中回答了这个问题,但这里是执行此操作的代码:

-(void) gameplay
{
    if (actionhappen)
    {
        CCActionCallFunc *checkWinner =
          [CCActionCallFunc actionWithTarget:self selector:@selector(checkWinner)];

        CCActionSequence *mySeq =
          [CCActionSequence actionWithArray:@[do,some,action, checkWinner]]; //note checkWinner

        [mySprite runAction:mySeq]; // it takes 3 seconds.
    }
    else
    {
        // in this case call the func directly
        [self checkWinner];
    }
}

-(void)checkWinner
{
    if (someoneWin)
    {
        // I want to wait here until mySeq action finished
        [self showWinnerMessage];
    }
}