在cocos2d中的runAction方法中需要一些帮助

时间:2010-05-26 13:11:49

标签: cocoa-touch cocos2d-iphone

我对CCAnimation有一点疑问。性能中的code1和代码2之间有什么区别吗?

代码1:

id Action1 = [CCAnimate actionWithAnimation: numberAnimation restoreOriginalFrame:NO];
        id Action2 = [CCFadeOut actionWithDuration:0.1f];
        id Action3 = [CCCallFunc actionWithTarget:self     selector:@selector(Method1:)];
        [player runAction: [CCSequence actions:Action1, Action2, Action3, nil]];

码2:

[player runAction: [CCSequence actions:  [CCAnimate actionWithAnimation: numberAnimation restoreOriginalFrame:NO],  [CCFadeOut actionWithDuration:0.1f], [CCCallFunc actionWithTarget:self selector:@selector(enemyGunDrawMethod:)], nil ] ];`

哪种写法更好,请解释原因?
谢谢。

1 个答案:

答案 0 :(得分:0)

在大多数情况下,性能差异并不值得担心。我会使用code1,因为它更具可读性。

主要区别在于记忆力。在code1中分配了三个不在code2中的指针。这些指针是短暂的,相对较小。在编译器优化之后,code1和code2可能是等效的。