CCProgressTimer的使用

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

效果如下:\

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//创建二个精灵,一个白色边框,一个逐渐增加的红心
     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中有:

?
1
2
3
4
5
6
kCCProgressTimerTypeRadialCW 顺时针生成
kCCProgressTimerTypeRadialCCW 逆时针生成
kCCProgressTimerTypeHorizontalBarLR 从左到右生成
kCCProgressTimerTypeHorizontalBarRL 从右到左生成
kCCProgressTimerTypeVerticalBarBT 从下到上生成
kCCProgressTimerTypeVerticalBarTB 从上到下生成

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

?
1
2
3
4
5
6
typedef enum {
  /// Radial Counter-Clockwise
  kCCProgressTimerTypeRadial,
  /// Bar
  kCCProgressTimerTypeBar,
} CCProgressTimerType;

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

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

学习的路上,与君共勉。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值