Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the same action on multiple sprites?

I want to create an action once, then add it to multiple sprites. For example, I have a 'monster' that gets a bunch of legs added to its body. Each of these legs are children of the body, and I want them to rotate back and forth. I made a CCRepeatForever of a sequence of two CCRotateBy actions which works great. I can add the action to a leg, but if I then add it to a different leg, the first leg doesn't rotate.

I don't want to make a new sequence for each leg - what a pain! There's gotta be an easy way!

EDIT:

I implemented it like this, per gixdev and Lukman's answers... (thanks AGAIN Lukman!)

[leg1 runAction:action]; // for the first time using the action
[leg2 runAction:[[action copy] autorelease]]; // for all subsequent uses
like image 966
Steve Avatar asked Jun 19 '11 21:06

Steve


1 Answers

If copy your once created actions it help you

[leg1 runAction:[action copy]];
[leg2 runAction:[action copy]];
...
like image 82
gixdev Avatar answered Oct 13 '22 12:10

gixdev