[已解决]关于SpriteBatchNode的疑问

在官方教程
https://github.com/cocos2d/cocos-docs/blob/master/tutorial/how-to-use-texturepacker-to-optimize-the-spritesheet/zh.md,1
中,

Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
Texture2D *texture2D = Director::getInstance()->getTextureCache()->addImage("sprites-hd.pvr.ccz");
auto spBatchNode = SpriteBatchNode::createWithTexture(texture2D);
addChild(spBatchNode);
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("sprites-hd.pvr.plist");
std::vector arrSpFrameName = {"bear_2x2.png","bird.png","cat.png","dog.png","ooze_2x2.png","turtle.png"};   

for(int i = 0;i< arrSpFrameName.size();i++){
    std::string spFrameName = arrSpFrameName.at(i);
    auto sp = Sprite::createWithSpriteFrameName(spFrameName);
    float offsetFaction = ((float)(i+1)/(arrSpFrameName.size()+1));
    Point spriteOffset = Point(visibleSize.width*offsetFaction,visibleSize.height/2);
    sp->setPosition(spriteOffset);
    addChild(sp);
}
```

添加各个精灵的代码addChild(sp)是不是应该改为spBatchNode->addChild(sp)?
可是奇怪的是两者运行后GL calls都是2,请问这是什么原因?

谢谢

应该是spBatchNode->addChild(sp)

感谢回复
可是为什么我实验下来
this->addChild(sp)和spBatchNode->addChild(sp)的GL calls(屏幕左下角的debug信息)都是2
难道this->addChild(sp)也能实现SpriteBatchNode的效果

你多添加几个就知道了 因为spBatchNode本身也有一个批次

spBatchNode->addChild(sp)的GL calls是2我可以理解,spBatchNode和layer一共两个描画对象
但是this->addChild(sp)的话spBatchNode应该没起到作用,GL calls应该是spBatchNode + layer + spritesheet里的八个png = 10
可是结果却是2,这是为什么?

这个估计是因为3.0的新特性吧:auto batching

原来是这样,谢谢

贴个说明给可能有同样疑问的人

Auto-batching means that the Renderer will package “multiple draw calls” in just one “big draw call” (AKA batch). In order to group “draw calls” certain conditions are needed:

It only works with QuadCommand commands (used by Sprite and ParticleSystem objects)
The QuadCommands must share the same Material ID: same Texture ID, same GLProgram and same blending function
The QuadCommands must consecutive

If those conditions are met, the Renderer will create create a batch (one draw call) with all thoseQuadCommand objects.
In case you are unfamiliar with the OpenGL best practices, batching is very important to have decent speed in your games. The less batches (draw calls) the more performance your game is going to be.

是的。3.0支持自动批处理渲染。

那我发的那篇就没用了呗。http://www.cocoachina.com/bbs/read.php?tid=196135

哪会,还没用上3.0的用户还有很多啊。