cocos2d 更换皮肤

前端之家收集整理的这篇文章主要介绍了cocos2d 更换皮肤前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

第一种:


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

} } }

猜你在找的Cocos2d-x相关文章