Reputation: 12433
-(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
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