In cocos2d-x, I have encountered the following problem when trying to define a CCSequence separately, i.e. not within runAction.
This works:
sprWheel1->runAction( CCSequence::actions(
CCDelayTime::actionWithDuration( fDelayTime ),
CCEaseExponentialOut::actionWithAction(
CCRotateBy::actionWithDuration( fMoveTime, fAngle ) ),
NULL
) );
sprWheel2->runAction( CCSequence::actions(
CCDelayTime::actionWithDuration( fDelayTime ),
CCEaseExponentialOut::actionWithAction(
CCRotateBy::actionWithDuration( fMoveTime, fAngle ) ),
NULL
) );
This does not work:
CCFiniteTimeAction* actRotate = CCSequence::actions(
CCDelayTime::actionWithDuration( fDelayTime ),
CCEaseExponentialOut::actionWithAction(
CCRotateBy::actionWithDuration( fMoveTime, fAngle ) ),
NULL
);
sprWheel1->runAction( actRotate );
sprWheel2->runAction( actRotate );
It does not cause a compiler error, or crash, or anything, it just doesn't rotate the sprite.
How can I fix this? (I am using this action multiple times, so it would really help to keep my code cleaner if I could define it only once)
A single instance of CCAction should not be used concurrently on multiple objects. The objects contained within the sequence maintain state on the current execution of the action, thus concurrent use on multiple objects will cause mayhem (cocos is possibly 'guarding' silently against that by stoping all actions, not certain). Best to have separate sequences for each sprite you want to animate. If you are concerned about code readability, just create a method in that class that will always return a fresh instance of the sequence.