stack of actions for one sparite in cocos2d

荒凉一梦 提交于 2019-12-25 04:05:32

问题


I've got a question: My games hero can jump (CCJumpTo) and move to forward and backward direction (CCMoveTo).

I faced with problem: if game recived a command from user to move the hero, but in this time hero is jumping (CCJumpTo), how can I do this command after the end of jumping. (can I use some stack of actions for one sparite in cocos2d)

I can't use immediately [self.sprite stopAllActions]; to begin CCMoveTo because the hero have to finish the jump action and if I use CCMoveTo the action CCJumpTo will not finish. Hero can't jump and start to move to forward and backward at height.

sorry for my English


回答1:


For example, you can store your stack of actions in array, then run action like this

- (void) runNextAction
{
    id actionFromStack = [stack objectAtIndex: 0];
    [stack removeObjectAtIndex: 0];
    id callback = [CCCallFunc actionWithTarget: self selector: @selector(runNextAction)];
    id sequence = [CCSequence actionOne: actionFromStack two: callback];
    [self runAction: sequence];
}


来源:https://stackoverflow.com/questions/10615729/stack-of-actions-for-one-sparite-in-cocos2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!