Cocos2d-js 3.2 技能冷却按钮的简单实现
来源:互联网 发布:迪杰斯特拉算法 编辑:程序博客网 时间:2024/05/01 20:59
一个简单的技能冷却按钮的实现
- var CoolButton = cc.Node.extend({ // 需要做成Node 否则会无法addchild
- callback : null, // 点击后的回调
- coolInterval : null, // 动画时间
- progressCooling : null, // 进度条
- sprNormal : null,
- sprStencil : null,
- menuBtn : null,
- ctor : function(resNormal, resPressed, resStencil, coolInterval, callback) {
- this._super();
- this.callback = callback;
- this.coolInterval = coolInterval;
- // menu item
- var btnItem = new cc.MenuItemImage(
- resNormal,
- resPressed,
- this.onBtnClick,
- this);
- // menu 默认在画面中间
- this.menuBtn = new cc.Menu(btnItem);
- this.menuBtn.attr({
- x : 0,
- y : 0
- });
- this.addChild(this.menuBtn, 0);
- // 图片覆盖在按钮上 造成无法点击的假象
- this.sprNormal = new cc.Sprite(resNormal);
- this.sprNormal.attr({
- x : 0,
- y : 0
- });
- this.addChild(this.sprNormal, 1);
- this.sprStencil = new cc.Sprite(resStencil);
- this.sprStencil.attr({
- x : 0,
- y : 0
- });
- this.addChild(this.sprStencil, 2);
- this.progressCooling = new cc.ProgressTimer(this.sprNormal);
- this.progressCooling.setType(cc.ProgressTimer.TYPE_RADIAL);
- this.progressCooling.setPercentage(0); // 回复到0
- this.progressCooling.attr({
- x : 0,
- y : 0
- });
- this.addChild(this.progressCooling, 5);
- this.progressCooling.setVisible(false);
- this.sprNormal.setVisible(false);
- this.sprStencil.setVisible(false);
- },
- onBtnClick : function() {
- // 设置按钮不可按
- this.menuBtn.setVisible(false);
- // 开始倒计时
- this.progressCooling.setVisible(true);
- this.sprNormal.setVisible(true);
- this.sprStencil.setVisible(true);
- this.progressCooling.runAction(cc.sequence(cc.progressTo(this.coolInterval, 100),
- cc.callFunc(this.coolEndCallback, this)));
- // 调用回调
- this.runAction(cc.callFunc(this.callback, this));
- },
- coolEndCallback : function() {
- this.menuBtn.setVisible(true);
- this.progressCooling.setVisible(false);
- this.progressCooling.setPercentage(0); // 回复到0
- this.sprNormal.setVisible(false);
- this.sprStencil.setVisible(false);
- }
- });
调用示例:
- var btn = new CoolButton(res.SkillNormal_png, res.SkillPressed_png, res.SkillStencil_png,
- 4, this.skill);
源引:http://blog.csdn.net/a102111/article/details/43637697
0 0
- cocos2d js 3.2 技能冷却按钮的简单实现
- Cocos2d-js 3.2 技能冷却按钮的简单实现
- cocos2d-x UI之技能冷却按钮
- cocos2d-x UI之技能冷却按钮
- cocos2d-x UI之技能冷却按钮
- cocos2d-x UI之技能冷却按钮
- cocos2d-x UI之技能冷却按钮
- Cocos2d-x CCProgressTimer实现DotA的技能冷却效果
- Cocos2d-x CCProgressTimer实现DotA的技能冷却效果
- [cocos2d-x] --- 实现Dota技能冷却效果
- [cocos2d-x] --- 实现Dota技能冷却效果
- Cocos2d-x 实现技能冷却效果
- [cocos2d-x] --- 实现Dota技能冷却效果
- 技能冷却时间的实现
- cocos2d-x 技能冷却
- cocos2d-x UI之技能冷却按钮 (转)
- Cocos2d-X 3.4版-技能冷却按钮《赵云要格斗》
- 【Cocos2d-x游戏引擎开发笔记(9)】实现DotA的技能冷却效果
- 高功耗的USR-WIFI232-2b的sta+ap配置可以使手机连上互联网
- HDU 3830 - Checkers(二分LCA)****
- 中国剩余定理 poj1006
- lua元表
- 安装post man
- Cocos2d-js 3.2 技能冷却按钮的简单实现
- C语言中的异常处理机制
- c:foreach标签使用详解
- ios软件开发 json格式字符串转字典,字典转json格式字符串
- 《SICP》读书笔记--Chapter 1 Building Abstraction with Procedures
- 多线程系列一——何为线程与java中线程的创建
- 编写更好的jQuery代码
- IOS应用信息抓取
- qt model中headerData()函数的调用