Cocos2d-x CCProgressTimer
来源:互联网 发布:微信能做淘宝客吗 编辑:程序博客网 时间:2024/06/06 09:01
CCProgressTimer,创建使用这个节点可以大致实现两个作用的效果:
其一:在游戏中几乎大部分的游戏启动界面都是游戏加载画面,那么用到的一般是进度条提示加载进度,其使用的就是CCProgressTimer。
其二:在游戏中需要对精灵的出现等动作制作一些渐显的效果。
(1)类型一般就是两种:
typedef enum { /// Radial Counter-Clockwise kCCProgressTimerTypeRadial, /// Bar kCCProgressTimerTypeBar,} CCProgressTimerType;
(2)类型1:radial(环形)
CCSize wSize = CCDirector::sharedDirector()->getWinSize(); progressTimer = CCProgressTimer::create(CCSprite::create("progress.gif")); progressTimer->setType(kCCProgressTimerTypeRadial); // 默认的情况下,环形渐变的方向是:顺时针 // 改变其渐变的方向 Makes the ridial CCW (逆时针) progressTimer->setReverseProgress(true); progressTimer->setPosition(wSize.width/2,wSize.height/2); this->addChild(progressTimer);
(3)类型2:bar (条形:包括vertical 和 horizontal)
渐变的方向问题:
vertical竖直方法包括从上到下和从下到上;
horizontal水平方向包括从左到右和从右到左。
这里涉及到两个设置参数:
首先是setMidpoint设置起点
/** * Midpoint is used to modify the progress start position. * If you're using radials type then the midpoint changes the center point * If you're using bar type the the midpoint changes the bar growth * it expands from the center but clamps to the sprites edge so: * you want a left to right then set the midpoint all the way to ccp(0,y) * you want a right to left then set the midpoint all the way to ccp(1,y) * you want a bottom to top then set the midpoint all the way to ccp(x,0) * you want a top to bottom then set the midpoint all the way to ccp(x,1) */
其次是setBarChangeRate设置变化rate
/** * This allows the bar type to move the component at a specific rate * Set the component to 0 to make sure it stays at 100%. * For example you want a left to right bar but not have the height stay 100% * Set the rate to be ccp(0,1); and set the midpoint to = ccp(0,.5f); */
如果不用变化的方向,则设置该方向为0,否则设置为1。
CCSize wSize = CCDirector::sharedDirector()->getWinSize(); progressTimer = CCProgressTimer::create(CCSprite::create("progress.gif")); progressTimer->setType(kCCProgressTimerTypeBar); //从左到右 progressTimer->setMidpoint(ccp(0, 0.5)); progressTimer->setBarChangeRate(ccp(1, 0)); //从右到左// progressTimer->setMidpoint(ccp(1, 0.5));// progressTimer->setBarChangeRate(ccp(1, 0)); //从上到下// progressTimer->setMidpoint(ccp(0.5, 1));// progressTimer->setBarChangeRate(ccp(0, 1)); //从下到上// progressTimer->setMidpoint(ccp(0.5, 0));// progressTimer->setBarChangeRate(ccp(0, 1)); progressTimer->setPosition(wSize.width/2,wSize.height/2); this->addChild(progressTimer);
(4) 执行变化
①、如果是要实现精灵渐变的显示效果:
创建CCProgressTo或者是CCProgressFromTo动作,让CCProgressTimer执行。
CCProgressTo和CCProgressFromTo的区别是:
前者:Progress to percentage(初始化有两个参数)(float duration, float fPercent)
后者:Progress from a percentage to another percentage(初始化有三个参数)(float duration, float fFromPercentage, float fToPercentage)
CCProgressTo *progressTo = CCProgressTo::create(2.0, 100); //等价于: //CCProgressFromTo *progressFromTo = CCProgressFromTo::create(2.0, 0, 100); progressTimer->runAction(CCRepeatForever::create(progressTo));
②、如果是要实现加载进度条的效果:
需要重载update方法,在这个方法中实现进度条percentage的变化。
this->scheduleUpdate();
void HelloWorld::update(float dt){ float percentage = progressTimer->getPercentage(); if (percentage < 100) { percentage += 1; progressTimer->setPercentage(percentage); }}
- Cocos2d-x CCProgressTimer
- [cocos2d-x]CCProgressTimer进度条
- cocos2d-x - CCProgressTimer详解
- cocos2d-x--CCProgressTimer
- Cocos2d-x CCProgressTimer
- Cocos2d-x之CCProgressTimer进度条
- cocos2d-x TestLua 之 CCProgressTimer
- cocos2d-x进度条CCProgressTimer详解
- cocos2d-x 2.x 进度条CCProgressTimer
- cocos2d-x之CCProgressTimer实现进度条
- cocos2d-x CCProgressTo和CCProgressTimer 使用
- Cocos2d-x基础: CCProgressTimer的使用
- cocos2d-x节点(CCProgressTimer.h)API
- cocos2D-x:CCProgressTimer图片特效(7)
- cocos2d-x 血量条 CCProgressTimer实现
- cocos2d-x初探学习笔记(7)--CCProgressTimer
- Cocos2d-x CCProgressTimer实现DotA的技能冷却效果
- Cocos2d-x CCProgressTimer实现DotA的技能冷却效果
- 取消异步回发
- Velocity源码分析
- [XMPP]我是怎么通过直接操作数据来为Openfire注册新用户的
- 个人学习和项目经验积累分享
- poj 1511 Invitation Cards
- Cocos2d-x CCProgressTimer
- 数据库 Connection的dispose和close方法差异
- Java InputStream读取网络响应Response数据的方法!(重要)
- Microsoft .NET框架和Visual Studio.NET中的SOAP
- POJ2524-并查集
- el表达式
- 《linux中cp和scp命令用法》
- 使用.NET存储XML数据
- 如何学习HTML语言