如何在cocos2d中执行当前操作(不停止当前操作并运行新操作)后执行操作

时间:2014-02-02 12:59:45

标签: cocos2d-iphone queue ccaction

我有一个在cocos2d中使用runAction的问题。

我想在触摸开始时运行动作,并在触摸结束时运行动作。像下面的代码一样实现:

-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event 
{
    CCActionInterval* zoomAction = [CCActionSequence actions:
    [CCActionScaleTo actionWithDuration:0.1 scale:m_zoomScale],nil];
    [self runAction:zoomAction];
}

-(void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event 
{
    CCActionInterval* zoomAction = [CCActionSequence actions:[CCActionScaleTo actionWithDuration:0.1 scale:1.0],nil];
    [self runAction:zoomAction];
}

但是,如果我在touchBegin动画完成之前触发touchEnded动画,它将跳过开始动画并开始直接运行结束动画。在当前sprite没有运行任何操作(比如向动作队列添加动作)之后,Cocos2d中有没有办法可以运行动作?

1 个答案:

答案 0 :(得分:2)

您可以尝试使用:

-(void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event 
{
    CCActionInterval* newZoomAction = [CCActionSequence actions:[CCActionScaleTo actionWithDuration:0.1 scale:1.0],nil];
    [self runAction:[CCSequence actions:self.actions, newZoomAction,nil]];
}