cocos2d-x CCSprite 更换图片 清空图片

1、更换图片

CCSprite * pImage = CCSprite::create("image.png");
CCTexture2D * text2d = CCTextureCache::sharedTextureCache()->addImage("other.png");
pImage->setTexture(text2d);
CCRect rect = CCRect(0, 0, text2d->getContentSize().width, text2d->getContentSize().height);
pImage->setTextureRect(rect);  // 要设置这个,图片才能保持other.png图片的大小,而且这句要在setTexture之后

2、清空图片

pImage->setTexture(NULL);
pImage->setTextureRect(CCRect());

原文地址:https://www.cnblogs.com/C-Plus-Plus/p/4092669.html