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?