使用单个精灵批量动画精灵更有效吗? (cocos2d的)

时间:2012-02-16 10:44:43

标签: animation cocos2d-iphone sprite textures batching

在cocos2d programming guide中有以下代码:

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。我的问题是:批量绘制单个动画精灵会比不使用批处理更有效吗?由于每次抽奖只绘制一个框架而且只有一个对象,我认为不会。如果你添加了多个对象,我认为唯一的好处就是它们可以在一次绘制中从相同纹理的框架坐标处绘制。我的推理是否正确?

1 个答案:

答案 0 :(得分:1)

感谢此处的回复:

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

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