cocos2d-x - CCProgressTimer详解

转自:点击打开链接

闲着想要实现一个功能。一个填充爱心的效果。

效果如下:


一个爱心填满动作。

为实现这个功能,学习了下CCProgressTimer , 顺便做个记录。


首先介绍几个相关链接:

dota道具冷却效果:http://blog.csdn.net/cen616899547/article/details/9084561

技能冷却效果:http://blog.csdn.net/z104207/article/details/8059098

CCProgressTimer相关讲解:http://blog.sina.com.cn/s/blog_73df887801019gnb.html

cocos2d-x学习笔记(3) CCProgressTimer倒计时条小记    http://my.eoe.cn/baimu/archive/3315.html
进度条准备工作解析CCProgressTimer类     http://www.zaojiahua.com/ccprogresstimer.html


好了。 进入正题。

CCProgressTimer是Cocos2d-x中用于显示进度的派生类。一般可用与加载进度条,道具冷却等效果。

具体也没其他内容,下面就通过上面的爱心填充源码讲解。

附带图片资源: (heart_A.png)(heart_B.png)

[cpp]  view plain  copy
  1. //创建二个精灵,一个白色边框,一个逐渐增加的红心  
  2.     CCSprite *psSprite1 = CCSprite::create("heart_A.png");  
  3.     CCSprite *psSprite2 = CCSprite::create("heart_B.png");  
  4.     //加载动作,设置5秒加载到100%  
  5.     CCProgressTo *progressTo = CCProgressTo::create(5, 100);  
  6.       
  7.     CCProgressTimer *heart_ = CCProgressTimer::create(psSprite2);  
  8.     //设置类型  
  9.     heart_->setType(kCCProgressTimerTypeBar);  
  10.       
  11.     //起始点. 从哪个方向开始变化  
  12.     heart_->setMidpoint(ccp(0, 0));  
  13.       
  14.     //ccp(1, 0) 水平方向 ccp(0, 1)垂直方向  
  15.     heart_->setBarChangeRate(ccp(0, 1));  
  16.       
  17.     psSprite1->setPosition(ccp(size.width/2, 500));  
  18.     addChild(psSprite1);  
  19.       
  20.     heart_->setPosition(ccp(size.width/2, 500));  
  21.     addChild(heart_);  
  22.       
  23.     heart_->runAction(CCRepeatForever::create(progressTo));  
具体的操作在代码中的给出了。很简单。


另外,需要注意一下。

在2.0中CCProgressTimer的type比1.0中少了很多,1.0中有:

[cpp]  view plain  copy
  1. kCCProgressTimerTypeRadialCW 顺时针生成  
  2. kCCProgressTimerTypeRadialCCW 逆时针生成  
  3. kCCProgressTimerTypeHorizontalBarLR 从左到右生成  
  4. kCCProgressTimerTypeHorizontalBarRL 从右到左生成  
  5. kCCProgressTimerTypeVerticalBarBT 从下到上生成  
  6. kCCProgressTimerTypeVerticalBarTB 从上到下生成 
而2.0中只保留了2个常用的。

[cpp]  view plain  copy
  1. typedef enum {  
  2.  /// Radial Counter-Clockwise  
  3.  kCCProgressTimerTypeRadial,  
  4.  /// Bar  
  5.  kCCProgressTimerTypeBar,  
  6. } CCProgressTimerType;  
不过,如果要实现一些效果,比如从下到上加载。如我给出的例子程序一样。只要设置好对应的setMidpoint, setBarChangeRate即可。

[cpp]  view plain  copy
  1. //起始点. 从哪个方向开始变化  
  2. heart_->setMidpoint(ccp(0, 0));  
  3.   
  4. //ccp(1, 0) 水平方向 ccp(0, 1)垂直方向  
  5. heart_->setBarChangeRate(ccp(0, 1));  


原文链接:点击打开链接


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值