1

我有一个在 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 动画,它将跳过开始动画并直接开始运行结束动画。Cocos2d 中是否有任何方法可以在当前精灵没有运行任何动作后运行动作(例如向动作队列添加动作)?

4

1 回答 1

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]];
}
于 2014-02-03T10:57:04.080 回答