cocos2dx:利用CCSpriteBatchNode优化渲染效率

生成精灵同城的方法是CCSprite::spriteWith**,用这种方法每生成一个精灵就进行渲染一次,如果需要渲染的精灵特别多,那就会影响效率。

CCSpriteBatchNode的原理是一次性的把需要渲染的精灵全部渲染,然后再生成精灵,在精灵特别多的时候优化效果会很明显。

1 CCSpriteBatchNode* batchNode = CCSpriteBatchNode::batchNodeWithFile("PackUnLock.png", 2000);
2     batchNode->setPosition(CCPointZero);
3     goodsPanel->addChild(batchNode);
4     for (int i=0; i<2000; i++) {
5         //CCSprite* cellBk = CCSprite::spriteWithFile("PackUnLock.png");
6         CCSprite* cellBk = CCSprite::spriteWithTexture(batchNode->getTexture());
7         cellBk->setPosition(goodPos[i].pos);
8         goodsPanel->addChild(cellBk);
9     }
原文地址:https://www.cnblogs.com/arthas/p/2790341.html