cocos2d-x CCSpriteBatchNode

转自:http://www.cnblogs.com/jiackyan/archive/2013/04/14/3019880.html

1、先说下渲染批次:这是游戏引擎中一个比较重要的优化指标,指的是一次渲染凋用。也就是说,渲染的次数越少,游戏的运行效率越高。
2、CCSpriteBatchNode就是cocos2d-x为了降低渲染批次而建立的一个专门管理精灵的类。

CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create("Icon.png", 1000); 
batchNode->setPosition(CCPointZero); 
this->addChild(batchNode); 
for(int i = 0;i < 1000;++i){ 
  int x = arc4random()%?; 
  int y = arc4random()%?; 
  CCSprite
* testIcon = CCSprite::createWithTexture(batchNode->getTexture());   testIcon->setPosition( ccp(x, y) );   batchNode->addChild(testIcon); }

3、

CCSpriteBatchNode::create(const char *fileImage);//利用贴图创建,默认子节点数量29.(数量不够时,系统会自己增加)
CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create(const char *fileImage, unsigned int capacity);//利用贴图创建,并指定子节点数量


4、使用CCSpriteBatchNode时,所使用的贴图必须是同一张图片,也不能指定精灵的深度。所有的精灵都必须在同一渲染层。
5、但是项目中总不可能局限于一张贴图上,所以你可以把多张贴图合并成一张大贴图(合并的工具很多,我不介绍了)。所以利用合成后的大贴图创建一个CCSpriteBatchNode。
然后创建CCSprite的时候,设置贴图的区域就可以了。

原文地址:https://www.cnblogs.com/sevenyuan/p/3191741.html