@zhangxm How to use the newest feature you said ‘In v3.x, engine can do auto-batching, so you don’t have to do it with SpriteBatchNode.’
I found all examples in Cocos v3 only support the old cache way that addChild in batchNode:
`SpriteBatchNode1::SpriteBatchNode1()
{
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(SpriteBatchNode1::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
auto BatchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);
addChild(BatchNode, 0, kTagSpriteBatchNode);
auto s = Director::getInstance()->getWinSize();
addNewSpriteWithCoords( Point(s.width/2, s.height/2) );
}
void SpriteBatchNode1::addNewSpriteWithCoords(Point p)
{
auto BatchNode = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
int idx = CCRANDOM_0_1() * 1400 / 100;
int x = (idx%5) * 85;
int y = (idx/5) * 121;
auto sprite = Sprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121));
BatchNode->addChild(sprite);
...
}`
If I want to use newest feature, should I change to:
`SpriteBatchNode1::SpriteBatchNode1()
{
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(SpriteBatchNode1::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
auto BatchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);
addChild(BatchNode, 0, kTagSpriteBatchNode);
auto s = Director::getInstance()->getWinSize();
addNewSpriteWithCoords( Point(s.width/2, s.height/2) );
}
void SpriteBatchNode1::addNewSpriteWithCoords(Point p)
{
//auto BatchNode = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
int idx = CCRANDOM_0_1() * 1400 / 100;
int x = (idx%5) * 85;
int y = (idx/5) * 121;
auto sprite = Sprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121));
this->addChild(sprite);
...
}`