How to run an action after the current action (not stopping the current action and run he new one) in cocos2d

StackOverflow https://stackoverflow.com/questions/21510867

  •  06-10-2022
  •  | 
  •  

質問

I have an issue of using the runAction in cocos2d.

I would like to run an action when the touch begin and run an action when touch is ended. Implemented like the code below:

-(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];
}

However, if I trigger the touchEnded animation before the touchBegin animation finished, it will skip the begin animation and start to run the end animation directly. Is there any way in Cocos2d can run an action after the current sprite is not running any actions(like add an action to an action queue)?

役に立ちましたか?

解決

You can try using:

-(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]];
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top