I have created a number of CCSprites using spriteWithFile.
How do I change the image for the sprite during runtime?
I need to change a few sprites images qui
i code cocos2D-x in c++ : when you use spriteSheet instead of using single file, you shoud use this method. suppose you add your spriteSheet in main layer.
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("sprite_sheet.plist");
_gameBatchNode = CCSpriteBatchNode::create("sprite_sheet.png", 200);
this->addChild(_gameBatchNode, kMiddleground);
kMiddleground is just a defined integer.
then i want to change picture of a sprite that already has a sprite with name "cloud.png" i use this code to do that:
cloud->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("blackCloud.png") );