cocos2d-x 之技能CD效果实现
会玩DOTA或者其他带有技能选项的游戏的玩家,应该都会知道每项技能两次施放间存有时间间隔,而在这段时间里,技能会被一个遮罩层动画覆盖以表示技能剩余冷却时间。
那么,这次,我就以实现该效果为目标,展示cocos2d-x中提供的各种CD效果吧。
先看看cocos2d-x中给我们提供了哪些效果吧~~
typedef enum {
/// 逆时针生成
kCCProgressTimerTypeRadialCCW,
/// 顺时针生成
kCCProgressTimerTypeRadialCW,
/// 从左到右生成
kCCProgressTimerTypeHorizontalBarLR,
/// 从右到左生成
kCCProgressTimerTypeHorizontalBarRL,
/// 从下到上生成
kCCProgressTimerTypeVerticalBarBT,
/// 从上到下生成
kCCProgressTimerTypeVerticalBarTB,
} CCProgressTimerType;
可以看到共有6种效果,那么很直接了当地把这6种效果全部枚举出来看看效果:
float mPercentage = 100; // 定义CD的显示百分比
ccTime cd_Time = 5.0f; // 定义CD的时间
int actionCount = 6; // 表示CD动画类型数量
CCProgressTimer* pt = NULL; // 声明一个进度条变量
for(int i=0; i<actionCount; i++)
{
pt = CCProgressTimer::progressWithFile("Icon.png"); // 设置进度条图样
pt->setPercentage(mPercentage); // 设置进度条最大百分比
pt->setPosition(ccp(size.width/2+100*(i%3-1), size.height/2+100*(i/3-1))); // 设置CD图样的位置
pt->setType(CCProgressTimerType(i)); // 设置进度条动画类型
this->addChild(pt);
CCProgressTo *to = CCProgressTo::actionWithDuration(cd_Time, mPercentage); // 设定CD时间与要到达的百分比
pt->runAction(to); // 给进度条加上动画条件
}
解释下CCProgressTimerType(i),这个表示取出枚举类型CCProgressTimerType中的第i个元素,以方便循环体的编写~~~
实现这个效果还是比较简单的,下面就上图~~~呵呵~
效果图:
资源图:


浙公网安备 33010602011771号