闲着想要实现一个功能。一个填充爱心的效果。
效果如下:
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
));
|
学习的路上,与君共勉。