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)


//创建二个精灵,一个白色边框,一个逐渐增加的红心
    CCSprite *psSprite1 = CCSprite::create("heart_A.png");
    CCSprite *psSprite2 = CCSprite::create("heart_B.png");
    //加载动作,设置5秒加载到100%
    CCProgressTo *progressTo = CCProgressTo::create(5, 100);
    
    CCProgressTimer *heart_ = CCProgressTimer::create(psSprite2);
    //设置类型
    heart_->setType(kCCProgressTimerTypeBar);
    
    //起始点. 从哪个方向开始变化
    heart_->setMidpoint(ccp(0, 0));
    
    //ccp(1, 0) 水平方向 ccp(0, 1)垂直方向
    heart_->setBarChangeRate(ccp(0, 1));
    
    psSprite1->setPosition(ccp(size.width/2, 500));
    addChild(psSprite1);
    
    heart_->setPosition(ccp(size.width/2, 500));
    addChild(heart_);
    
    heart_->runAction(CCRepeatForever::create(progressTo));

具体的操作在代码中的给出了。很简单。


另外,需要注意一下。

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

kCCProgressTimerTypeRadialCW 顺时针生成
kCCProgressTimerTypeRadialCCW 逆时针生成
kCCProgressTimerTypeHorizontalBarLR 从左到右生成
kCCProgressTimerTypeHorizontalBarRL 从右到左生成
kCCProgressTimerTypeVerticalBarBT 从下到上生成
kCCProgressTimerTypeVerticalBarTB 从上到下生成

而2.0中只保留了2个常用的。

typedef enum {
 /// Radial Counter-Clockwise
 kCCProgressTimerTypeRadial,
 /// Bar
 kCCProgressTimerTypeBar,
} CCProgressTimerType;

不过,如果要实现一些效果,比如从下到上加载。如我给出的例子程序一样。只要设置好对应的setMidpoint, setBarChangeRate即可。

//起始点. 从哪个方向开始变化
heart_->setMidpoint(ccp(0, 0));

//ccp(1, 0) 水平方向 ccp(0, 1)垂直方向
heart_->setBarChangeRate(ccp(0, 1));

学习的路上,与君共勉。


  • 23
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Colin丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值