Cocos2d-x ProgressTimer的简单使用

作者 qiuzhong 日期 2016-02-16
Cocos2d-x ProgressTimer的简单使用

开发过程中需要一个类似于游戏技能冷却的效果

Sprite* progressSprite = Sprite::create("headportrait/time_clock_bg.png");
mProgressTimer = ProgressTimer::create(progressSprite);
this->addChild(mProgressTimer, 100);
mProgressTimer->setType(ProgressTimer::Type::RADIAL);//设置进度条的形状
mProgressTimer->stopAllActions();//停止动画
mProgressTimer->setReverseProgress(true);//设置是逆时针

准备一个20秒旋转360度的动画(逐渐覆盖半透模板形成冷却效果;这里进行计时冷却动画的实现和时间控制)

ActionInterval* action_progress_to = Sequence::create(ProgressFromTo::create(20, 100, 0), nullptr);
ProgressFromTo 从多少百分比到多少百分比的时间
auto action_callback = CallFunc::create(CC_CALLBACK_0(PlayerBase::timeOverCallBack, this));
mProgressTimer->runAction(Sequence::create(action_progress_to, action_callback, NULL));

差不多就是这样了