Cocos2D:为不同的sprite重复使用动画 [英] Cocos2D: Reuse animation for different sprites

查看:172
本文介绍了Cocos2D:为不同的sprite重复使用动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一系列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重复使用动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆