1

在 cocos2d编程指南中有以下代码:

CGSize s = [[CCDirector sharedDirector] winSize];
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"grossini_dance_01.png"];
sprite.position = ccp( s.width/2-80, s.height/2); 

CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"animations/grossini.png"];
[batchNode addChild:sprite];
[self addChild:batchNode];

NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 1; i < 15; i++) {
    CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"grossini_dance_%02d.png",i]];
    [animFrames addObject:frame];
}
CCAnimation *animation = [CCAnimation animationWithName:@"dance" delay:0.2f frames:animFrames];
[sprite runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO] ]];

它以帧数组的形式添加一个简单的动画,并将用于动画这些帧的精灵添加到 CCSpriteBatchNode 中。我的问题是:批量绘制单个动画精灵会比不使用批处理更有效吗?由于每次绘制只绘制一帧并且只有一个对象,我认为不会。我认为唯一的好处是如果您添加了多个对象 - 这样它们就可以在一次绘制中从同一纹理在其帧坐标处绘制。我的推理正确吗?

4

1 回答 1

1

感谢这里的回复:

http://www.cocos2d-iphone.org/forum/topic/29354?replies=3#post-144515

至少有一个人已经确认它对一个对象没有任何好处,但可能会因增加的复杂性而略微降低性能。

于 2012-02-16T11:17:36.403 回答