what do you mean when you are saying that sprite is selected ?
Are you saying that when the sprite is touched, you need to change the texture…??
You know what. It doesn’t matter what I am trying to achieve really. Why does it matter? Gonna suggest another way to do it? That this is better than this than that, blah blah. I don’t need it to quite honest. I am asking a question. I just want to know how to replace the sprite texture dynamically. If it ever possible at all.
The good news is,all of the previous suggestions and my attempts work. What’s weird is that, the new texture is on the bottom of the old one, I checked the documentation and found a method under Sprite class named as setGlobalZOrder():
void Object::replaceSprite(const string & resourceName , int zIndex)
cocos2d::SpriteFrameCache * spriteFrameCache = cocos2d::SpriteFrameCache::sharedSpriteFrameCache();
cocos2d::SpriteFrame * spriteFrame = spriteFrameCache->getSpriteFrameByName(resourceName);
This currently work on my cocos2d-x exercise. I don’t know how will the setGlobalZOrder will scale with other sprite on but that is another discussion. I am going to read more about that function and its implementation later this evening. So that’s how I done it. I hope this will help someone in the future, just in case.
Thanks everyone for the help!