头文件的定义:
class HelloWorld : public @H_404_11@Layer
{
public:
ProgressTimer * progressTimer;
MenuItemImage * mi;
Menu *m;
Sprite * sprite;
Size s;
/** 技能按钮点击回调 */
@H_404_11@void skillClickCallBack(Ref* obj);
/** 技能冷却完毕回调*/
@H_404_11@void skillCoolDownCallBack(Node* node);
}在init初始化方法中加入:
//正常显示按钮
@H_404_11@ mi@H_404_11@ = MenuItemImage@H_404_11@::create@H_404_11@("skill_1.png"@H_404_11@,"skill_1.png"@H_404_11@,CC_CALLBACK_1@H_404_11@(HelloWorld@H_404_11@::skillClickCallBack@H_404_11@,this@H_404_11@));
mi->setPosition(Vec2(s.width/2,s.height/2));
m = Menu::create(mi,nullptr);
m->setPosition(Vec2::ZERO);
this->addChild(m);
然后是回调的方法
/** 技能按钮点击回调 */
@H_404_11@void HelloWorld::skillClickCallBack(Ref* obj)
{
//设置按钮不可用
mi->setEnabled(@H_404_11@false);
//灰模板按钮
sprite = Sprite::create("stencil.png");
sprite->setOpacity(160);
sprite->setPosition(Vec2(s.width/2,s.height/2));
progressTimer = ProgressTimer::create(sprite);
progressTimer->setPosition(Vec2(s.width/2,s.height/2));
@H_404_11@this->addChild(progressTimer);
// 设置精灵进度条为顺时针
progressTimer->setType(ProgressTimer::Type::RADIAL);
/** 让进度条执行一个动作 显示出动画效果 逐渐覆盖半透模板形成冷却效果;这里进行计时冷却动画的实现和时间控制*/
@H_404_11@auto pto = ProgressTo::create(2,100);
@H_404_11@auto call = CallFuncN::create(@H_404_11@this,callfuncN_selector(HelloWorld::skillCoolDownCallBack));
progressTimer->runAction(Sequence::create(pto,call,@H_404_11@NULL));
}
/** 技能冷却完毕回调*/
@H_404_11@void HelloWorld::skillCoolDownCallBack(Node* node)
{
//恢复触摸
mi->setEnabled(@H_404_11@true);
//隐藏
progressTimer->setVisible(@H_404_11@false);
}
效果如图所示: