CCSpriteBatchNode problem

Hello

In working on some game with Cocos2d-x
I need to change ship sprite dynamically and i used the following code for that

in init method
batchNode = CCSpriteBatchNode::create(“Ship.pvr.ccz”);
layer~~>addChild;
CCSpriteFrameCache::sharedSpriteFrameCache~~>addSpriteFramesWithFile;
sprite = CCSprite::createWithSpriteFrameName;
batchNode~~>addChild;
and in update method
sprite~~>initWithSpriteFrameName(“ship.png”);

so i want to dynamically change main sprite displayed on screen. It was working fine when when sprite was added directly to the scenere layer
but then i changed it from
scene~~>addChild;
to
batchNode~~>addChild(sprite);
and now code with sprite->initWithSpriteFrameName(“ship.png”) doesnt work.

So i guess i do something wrong and not possible to change sprite on the fly from SpriteBatchNode by calling initWithSpriteFrameName function.
I went through Sprite api and couldn’t find any good method for it.

can somebody advice what to use in this situation?
do i need to create list of sprites for each file name and then just dynamically add/remove it from batch node?
or may be it’s better to work directly with scene layer as it worked before?

Hi Dennis, what is the error that you are getting. That might be helpful if you provided what the compiler is not happy with. You should be able to add sprites to a spriteBatch, it is there to help reduce draw calls. Call this line before creating the Spritebatch: CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(“Ship.plist”);

Secondly, make sure to check that the sprite name is typed correctly. Also if you are using a SpriteBatching tool like TexturePacker, it allows to truncate the extension. Make sure you are checking for that and typing the sprite name correctly. Cocos2D is case sensitive about sprite names.