CCSpriteBatchNode problem !!!

I had a CCSprite and add it to SpriteBatchNode like this

CCSprite* sprite;
sprite = CCSprite::spriteWithSpriteFrameName(listBLockFrameName[“image.png”);
sprite~~>setTag;
spriteBatch~~>AddChild(sprite);

Then I get and modified it like this :

CCSprite* sprite = spriteBatch->getChildByTag(0);

sprite = CCSprite::initWithSpriteFrameName( “image2.png” );

Then it crash the game @@

Can someone explain it to me. Thanks for reading and sorry about my bad english.

I’m confused by your code.
Please refer to the SpriteTest.cpp to use CCSpriteBatchNode.

In your case, it should looks like

CCSpriteBatchNode* batchNode = CSpriteBatchNode::create("image.png");
batchNode->setTag(0);
this->addChild(batchNode);

CCSprite* sprite = CCSprite::spriteWithTexture(batchNode->getTexture(), CCRectMake(x,y,width,height));
batchNode->addChild(sprite);

Make sure that the parent-children relationship must be: layer->batchNode->sprite

Here is how I use this

CCSpriteFrameCache::sharedSpriteFrameCache()>addSpriteFramesWithFile; // “pList” is my sprite .plist file export from Texture packer
spriteBatch = CCSpriteBatchNode::batchNodeWithFile; // “fileName” is my sprite sheet export from Texture packer
this
>addChild( spriteBatch ); // “this” is my layer :slight_smile:
>
CCSprite* sprite = CCSprite::spriteWithSpriteFrameName( “image.png” );
sprite~~>setTag;
spriteBatch~~>addChild(sprite);

And some where in my update code I’m going to do this

CCSprite* sprite = (CCSprite*) spriteBath~~>getChildByTag ;
sprite~~>initWithSpriteFrameName( “image2.png” );

Then it crash , I find out that before this line

sprite->initWithSpriteFrameName( “image2.png” );

My sprite has m_bUsesBatchNode = true;

And after initWithSpriteFrameName it has m_bUsesBatchNode = false; @@ and crashed my game !