cocos2d-x CCSprite 更換圖片 清空圖片

一、更換圖片spa

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以後圖片

二、清空圖片get

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

相關文章
相關標籤/搜索