cocos2d js 3.2 技能冷却按钮的简单实现

cocos2d js 3.2 技能冷却按钮的简单实现,第1张

概述一个简单的技能冷却按钮的实现 var CoolButton = cc.Node.extend({ // 需要做成Node 否则会无法addchild callback : null, // 点击后的回调 coolInterval : null, // 动画时间 progressCooling : null, // 进度条 sprNormal : null, sprStencil : nu

一个简单的技能冷却按钮的实现

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,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);

参数依次为:

普通状态图片资源,按下状态图片资源,遮罩层图片资源,冷却时间,按钮按下回调

总结

以上是内存溢出为你收集整理的cocos2d js 3.2 技能冷却按钮的简单实现全部内容,希望文章能够帮你解决cocos2d js 3.2 技能冷却按钮的简单实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1038820.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存