1 / 13
文档名称:

游戏开发引擎—Cocos2d-x自定义血条其美化--之游戏开发《赵云要格斗》(4).doc

格式:doc   页数:13页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

游戏开发引擎—Cocos2d-x自定义血条其美化--之游戏开发《赵云要格斗》(4).doc

上传人:2028423509 2016/3/12 文件大小:0 KB

下载得到文件列表

游戏开发引擎—Cocos2d-x自定义血条其美化--之游戏开发《赵云要格斗》(4).doc

文档介绍

文档介绍:.页眉. .页脚. 游戏发开引擎— Cocos2d-x 自定义血条及其美化-- 之游戏开发《赵云要格斗》(4) 本文关键词:游戏引擎,游戏开发引擎, cocos 引擎 html5 游戏开发本章要讲解给怎么在界面上加一个血条, 老规矩, 还是在《 Cocos2d-x 地图随精灵无限滚动与边缘检测-- 之游戏开发《赵云要格斗》(三) 》的基础上进行增加功能的。在游戏开发中, 血条是一个很重要的东西, 这里的血条是通过两个图片来完成, 一个是前景图( 红色), 一个是背景图( 灰色), 通过改变红***在长度显示, 灰***不变就可实现血量的变化了。当然,这里为了让界面更加好看些,又为血条加了个血框和人物的小头像。 Cocos2d-x 版本: 工程环境: Windows7+VS2010 先来看看效果吧( 由于还没有引入怪物, 所以我弄成攻击一次, 血条少 1或 10 两种来看看效果): .页眉. .页脚. 一、自定义血条类本着后头血条要给怪物来用,所以设计了一个血条类。sprite 对像,控制前景示的大小就可以改变血量了。首先是资源,在 Resources 添加以下图片红血条( 前景): 灰血条( 背景): 血条框架: 赵云左上角小头像: 头文件 : 12345 #ifndef __PROGRESSVIEW_H__ #define __PROGRESSVIEW_H__ #include "" using namespace cocos2d; .页眉. .页脚. 6789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 class ProgressView : Node { public: ProgressView(); public: //设置血条背景 void setBackgroundTexture(const char *pName); //设置血条前景 void setForegroundTexture(const char *pName); //设置总血量 void setTotalProgress(float total); //设置当前血量 void setCurrentProgress(float progress); //得到当前血量 float getCurrentProgress() const; //得到总血量 float getTotalProgress() const; private: //. .页脚. 28 29 30 31 32 33 34 35 36 37 38 void setForegroundTextureRect(Rect &rect); private: CCSprite *m_progressBackground;// Sprite *m_progressForeground;// 前景血条 float m_totalProgress;// 总血量 float m_currentProgress;// 当前血量 float m_scale;// 放大倍数}; #endif 实现文件 : 123456789 #include "" ProgressView::ProgressView() : m_progressBackground(NULL) , m_progressForeground(NULL) , m_totalProgress() , m_currentProgress() , m_scale() { .页眉. .页脚. 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 } void ProgressView::setBackgroundTexture( const char *pName ) { m_progressBackground = CCSprite::create(pName); this->addChild(m_progressBackground); } void ProgressView::setForegroundTexture( const char *pName ) { m_progressForeground = CCSprite::create(pName); m_progressForeground->p(, ));// 设置锚点 m_progressForeground->p(-m_progressForeground->ge