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

本文介绍了如何在cocos2d-js 3.2版本中创建并实现一个简单的技能冷却按钮,包括按钮的普通状态、按下状态、遮罩层效果及冷却时间显示,并提供了调用示例和按钮按下回调功能。
摘要由CSDN通过智能技术生成

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

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值