-(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操作完成?
Sleep()似乎使一切都进入睡眠状态。
好吧,@ 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];
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句