Jonny
Jonny

Reputation: 16298

One action for several CCNode

I'm creating an action like this

id action = [CCRepeatForever actionWithAction:
                [CCSequence actions:
                    [CCMoveTo actionWithDuration:TIMESPEED position:POINT_TOP],
                              [CCMoveTo actionWithDuration:TIMESPEED position:POINT_START],
                              nil]];

I'd like to run this on several nodes

                for (Myitem* bonusitem in self.bonusitems) {
                    [bonusitem runAction:action];
                }

This crashes. If I do [bonusitem runAction:[action copy]] instead each time it works but I assume that I am responsible of releasing the action too. However, doing so also always crashes. So I just leave those unreleased and it works but AFAIK this would go against the copy rule now wouldn't it? (the copied actions would never be deallocated thus causing memory leaks)

Upvotes: 0

Views: 59

Answers (1)

Morion
Morion

Reputation: 10860

You can check the code of any action subclass. You'll see that action's copy returns as autoreleased object. So you can use it's copies freely. You cannot use any action more than once.

Upvotes: 1

Related Questions