Reputation: 1670
Currently I have a series of sprites (cardA, cardB, cardC) and series of actions ( flipCardA, flipCardB, flipCardC ) which I initialize in init method.
I want to get rid of 2 unnecessary actions and just have one action flipCard, but I can't figure out and couldn't find anything on: "how can I apply the same action to different sprites."
the test I have (which applies action only to third card):
[self.cardA runAction:self.flipCard];
[self.cardB runAction:self.flipCard];
[self.cardC runAction:self.flipCard];
so I currently have to use something like that:
[self.cardA runAction:self.flipCardA];
[self.cardB runAction:self.flipCardB];
[self.cardC runAction:self.flipCardC];
Thanks.
Upvotes: 0
Views: 987
Reputation:
You can't use single CCAction for multiple CCSprites simultaneously. runAction sets the CCAction's target property to the class object that runAction is called from, overriding any previous value of target.
You can do [self.flipCard copy]
or continue doing like you're doing. Or better yet, contain the flip animation construction and execution within a method in your card class-- say [self.cardA flipCard]
-- then call that instead. Now you don't have to worry about keeping explicit copies of the flip animation.
The cost of recreating the flip animation each time is negligible, but you can hold the CCSequence you create in a class variable to use repeatedly.
Upvotes: 1