加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx番外篇——更换精灵图片

发布时间:2020-12-14 21:37:37 所属栏目:百科 来源:网络整理
导读:本文出自 “ 夏天的风 ” 博客,请务必保留此出处 http://www.jb51.cc/article/p-zgvkqwcf-wx.html 1、直接通过图片更换 使用setTexture(CCTexture2D*)函数,可以重新设置精灵类的纹理图片。 1 2 3 4 // CCTexture2D*texture=CCTextureCache::sharedTextureC

本文出自 “夏天的风” 博客,请务必保留此出处http://www.52php.cn/article/p-zgvkqwcf-wx.html


1、直接通过图片更换

使用setTexture(CCTexture2D*)函数,可以重新设置精灵类的纹理图片。

1
2
3
4
//
CCTexture2D*texture=CCTextureCache::sharedTextureCache()->addImage( "bg2.png" );
bg->setTexture(texture);
//

2、通过缓存帧替换

使用setDisplayFrame(CCSpriteFrame*)函数,利用精灵帧更换精灵图片。

4
5
6
7
8
9
10
11
//加载plist文件到缓存
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile( "bg_0.plist" );
//使用精灵帧,创建精灵
CCSprite*bg=CCSprite::createWithSpriteFrameName( "bg1.png" );
//更换精灵图片
CCSpriteFrame*frame=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName( );
bg->setDisplayFrame(frame);
//



3.initWithFile

pSprite->initWithFile("game_bg2.jpg");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

相关内容
推荐文章
站长推荐
热点阅读