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?

- 20,959
- 28
- 93
- 149

- 224
- 3
- 17
2 Answers
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.

- 9,070
- 8
- 35
- 48
-
Just discovered that this won't work because it stops the action before it is completed. This action is an animation with repeat forever so this solution will not work. – stenger96 Jul 09 '12 at 20:40
-
so if it runs forever, what was the point of running it again ? – YvesLeBorg Jul 09 '12 at 20:53
-
I'm trying to start the action is a CCRepeatForever (I posted the actual action above) when the player is moving up. I have that part figured out. But since it checks to see which direction the player is moving in every update I get the error, Can't run CCAction, Action already running. So I need to know how to work around this. Sorry if my original post wasn't clear enough. – stenger96 Jul 09 '12 at 22:03
-
Yea thats what I ended up doing, even made one for standing still. Now if only I was a better animator... – stenger96 Jul 11 '12 at 13:33
-
hahaha ... well, sowwwwy cant help you too too much on that front. Best of luck with your game. – YvesLeBorg Jul 11 '12 at 14:01
In cocos2d you must recreate action before run, i.e. you cannot run the same action several times. So, it is no need to save your action in variable if you don't want to stop only this action, not the others. This is about your error. If you tell a bit more details, what are you trying to do with your walkUpAction
, I can try to give you few suggestions about how to do what you want.
Actually, i don't know how do this joystick works, but if it does not store previous state, you can store it manually and run your action in case of previous velocity of 0 and current velocity more than 0. And, anyway you must recreate action before run it again. So, you will have something like this
- (void) update:(ccTime)dt
{
BOOL needRunWalkUpAnimation = (prevVelocity == 0) && (curVelocity > 0);
if( needRunWalkUpAnimation )
{
id walkUpAction = \\create your action here
[player runAction: walkUpAction];
}
prevVelocity = curVelocity;
}

- 10,495
- 1
- 24
- 33
-
This is the walkUpAction: `self.walkUpAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkUpAnim restoreOriginalFrame:NO]];` – stenger96 Jul 09 '12 at 11:17
-
-
it does not matter. anyway you can store current velocity as previous value – Morion Jul 09 '12 at 11:52
-
I don't think this is true. I have created several games where the game hero char has his actions defined in his init. I use this actions on and off all the time throughout the game, never recreating them. Like actions for walking, jumping, falling etc. I store them in properties and stop all actions before running any of them. – Jonny Sep 20 '13 at 08:33