1
在cocos2d的programming guide有以下代码:使用单个精灵进行批处理动画精灵效率更高吗? (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子画面。我的问题是:将批处理绘制一个单一的动画精灵比没有使用批处理更高效吗?由于在每次抽奖和只有一个对象只画出一帧,我不会这么想。我认为唯一的好处是如果你添加了多个对象 - 这样他们就可以在同一个纹理中以相同的纹理绘制在他们的框架坐标上。我的推理是否正确?
我可以证实这一点。对于单个精灵来说,配料是有害的。 – LearnCocos2D 2012-02-16 23:19:53