Question

I have a CCSprite "_wo1" and it has a BOOL property "attack". I have the following code in my update method and I want it to constantly check if "attack" is YES or NO and make my sprite do different kinds of runAction.

So my question is:

How to compare two runAction? I tried "==" and "isEqual" and they are not working..

MySprite *_wo1 = ... // initialize _wo1 using my own class that sub-classed CCSprite
    if (![_wo1 attack])
    {
        _wo1.position = ccp(_wo1.position.x + 10 * dt, _wo1.position.y); // walking forward
        if (currentAction == attAction) // currentAction is defined in setting its runAction in the beginning: "currentAction = [wo1 runAction:[s01WalkAction copy]];"
        {
            [_wo1 stopAction:attAction];
            [_wo1 runAction:[walkAction copy]];
        }
    }
    else{
        if (currentAction == walkAction)
        {
            [_wo1 stopAction:walkAction];
            [_wo1 runAction:[attAction copy]];
        }

    }

Any helps or suggestions will be highly appreciated. Thank you!

Was it helpful?

Solution

You can keep an action state of your sprite in the MySprite class which easily can tell you which action is used in the sprite.

When you run an action on the sprite just set the state properly. For example :

mySprite.actionState = ACTION_WALKING;

and then you can easily check which action is used:

  if (mySprite.actionState == ACTION_WALKING)
        {
           // Your handling code
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top