目前我有一系列sprite(cardA,cardB,cardC)和一系列动作(flipCardA,flipCardB,flipCardC),我在init方法中初始化。
Currently I have a series of sprites (cardA, cardB, cardC) and series of actions ( flipCardA, flipCardB, flipCardC ) which I initialize in init method.
我想摆脱2个不必要的动作,只有一个动作flipCard,但我不能弄清楚,并找不到任何东西:我如何应用相同的动作到不同的精灵。
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];谢谢。
推荐答案您不能同时对多个CCSprites使用单个CCAction。 runAction将CCAction的目标属性设置为调用runAction的类对象,覆盖任何以前的target值。
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.
您可以执行 [self。 flipCard copy] 或继续做你喜欢的事情。或者更好的是,在你的卡类中一个方法中包含翻转动画的构造和执行 - [self.cardA flipCard] - 然后调用它。现在你不必担心保持翻转动画的显式副本。
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.
每次重新创建翻转动画的成本是可以忽略的,但是你可以持有CCSequence您在类变量中创建以重复使用。
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.
更多推荐
Cocos2D:为不同的sprite重复使用动画
发布评论