animationcocos2d-iphoneccaction

Cocos2d CCAction already Running app termination


I am trying to animate my player for walking directions (like in a birds-eye-view RPG) so I have it if (joystick.velocity. y > 0){ [player runAction: walkUpAction] } of course this causes the problem of Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'runAction: Action already running I get that. What I don't get is a way to work around this. I've tried adding some variables (isRunning, if is running then don't call type thing) but nothing seems to work. I've asked this on the cocos2d forum but no luck. Any ideas?


Solution

  • Try this:

    first declare some iVars in the .h

    BOOL _isWalkingUp;
    BOOL _isWalkingDown;
    BOOL _isWalkingLeft;
    BOOL _isWalkingRight;
    

    then, in each section of code where you detect a direction change:

    if(!_isWalkingUp && ( joystick.velocity.y >0 ) ) {
        [player stopAllActions];
        [player runAction:walkUpAction];
        _isWalkingUp=YES;
        _isWalkingDown=NO;
        _isWalkingLeft=NO;
        _isWalkingRight=NO;
    }
    

    etc .... you will probably want to add some 'state' to avoid a jerky motion control. But this would be some kind of a start.