CCSprite->setTexture() dont work with spriteFrameByName()

Hello.

I try to change texture in my sprite on the fly. Here is my code:

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("img/share_atlas.plist", "img/share_atlas.png");

CCSprite *pView = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("grid.png"));
//OK sprite is white quad - grid.png

CCSprite *pGreen = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("green.png"));
pView->setTexture(pGreen->getTexture());
//NOT OK sprite still white

pGreen = CCSprite::spriteWithFile("green.png");
pView->setTexture(pGreen->getTexture());
//OK sprite is green

But i like to use sprite atlas, and dont like use standalone sprites;

I think you should set texture rect after you setting texture for a sprite.
So, try it like this

CCSprite *pGreen = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("green.png")); 
pView->setTexture(pGreen->getTexture());
pView->setTextureRect(...); // set texture rect here

Thanks a lot. I thought of it last night.

pView->setTextureRect(pGreen->getTextureRect());

Work fine.