I have a problem with an action performed by a sprite. I have one CCSequence in a CCArray and I have an scheduled method (is called every 5 seconds) that make the sprite run the action. The action is performed correctly only the first time (the first 5 seconds), after that, it does not.

Hi! Thanks for your answer, I've tested it and it works! How safe is this solution? Thanks!
–
AxortApr 9 '12 at 17:32

Absolutely safe, if you check CCAction implementations you see that init is used to duplicate the action. That's why copy will actually (as usually) increase the retain count and that's finally why you need to autorelease it. Even because it will be retained again by adding it as a running action of the CCNode.
–
JackApr 9 '12 at 17:51

As far as I know CCAction classes are designed to run only once. You cannot re-use them.

The only way I'm aware of is to call the init method (eg. initWithDuration) of the action again, but this is bad practice, because init should only be called once after construction of the object and might lead to memory-leaks or other issues if called multiple times.

In your case I suggest you modify your createTrajectories function to build and return a new CCSequence every time (so simply return waveTrajectory instead of adding it to the array). Then in your spawn function, you could do something like:

Hi! Thanks for your answer. That's indeed a good solution. What do you think about the solution given by Jack?
–
AxortApr 9 '12 at 17:37

@Axort I think they are about equal. Both will allocate a new object. Personally I would rather use my proposal, because I think it is more readable and understandable where stuff gets allocated etc.
–
bummzackApr 9 '12 at 20:03