第一种:
CCSprite*_pHookSp = CCSprite::create("hook.png");
addChild(_pHookSp);void Hook::setDisplayFrame()
{
if (_pHookSp)
{
//需要更换图片时
//CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hook_2.png");
//_sp->setDisplayFrame(frame);
CCTexture2D* pTexture;
if (_pBindMine)
pTexture = CCTextureCache::sharedTextureCache()->addImage("hook_2.png");
else
pTexture = CCTextureCache::sharedTextureCache()->addImage("hook.png");
_pHookSp->setTexture(pTexture);
}
}
第二种:
sfc = CCSpriteFrameCache::sharedSpriteFrameCache();
sfc->addSpriteFramesWithFile("store.plist");
CCSprite* _pHookSp= CCSprite::createWithSpriteFrame(sfc->spriteFrameByName("hook.png"));
void Hook::setDisplayFrame()
{
if (_pHookSp)
{
//需要更换图片时
CCTexture2D* pTexture;
if (_pBindMine)
{
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hook_2.png");
_pHookSp->setDisplayFrame(frame);
}
else
{
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hook_2.png");
_pHookSp->setDisplayFrame(frame);
} } }