whitebear
whitebear

Reputation: 12433

Wait method run until CCActionSequence finishes

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

in this code

[self showWinnerMessage] runs before mySeq finished.

How can I wait until the mySprite action finished?

Sleep() seems to make everything sleep.

Upvotes: 0

Views: 76

Answers (1)

Insomniac
Insomniac

Reputation: 3384

Well, @LearnCocos2D already answered this question in comments, but here is the code to do this:

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

Upvotes: 1

Related Questions