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());

posted @ 2014-11-12 16:47  猿走天下  阅读(685)  评论(0编辑  收藏  举报