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
  •  | 
  •  

Question

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)?

Was it helpful?

Solution

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]];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top