cc.Class({ extends: cc.Component, editor: { menu: 'Debug/DebugCtrl' }, properties: { btnNode: cc.Node, _prevX: 0, _prevY: 0, _didMove: false }, onEnable () { this.btnNode.on(cc.Node.EventType.TOUCH_START, this._onTouchStart, this); this.btnNode.on(cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this); this.btnNode.on(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this); this.btnNode.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchEnd, this); cc.tween(this.btnNode) .delay(1) .to(1, {opacity: 0}) .start(); }, onDisable () { this.btnNode.off(cc.Node.EventType.TOUCH_START, this._onTouchStart, this); this.btnNode.off(cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this); this.btnNode.off(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this); this.btnNode.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchEnd, this); }, onClicked () { G.AppUtils.getSceneCtrl().showAlert('edt_prefab/Debug/debug_alert', undefined); }, _onTouchStart (event) { let location = event.getLocation(); this._didMove = false; this.btnNode.stopAllActions(); this.btnNode.opacity = 255; this._prevX = location.x; this._prevY = location.y; }, _onTouchMove (event) { let location = event.getLocation(); let posX = this.btnNode.x; let posY = this.btnNode.y; if (!this._didMove) { let deltaV2 = cc.v2(posX, posY).sub(cc.v2(location.x, location.y)); let dist = deltaV2.mag(); if (dist > 44) { this._didMove = true; } } if (this._didMove) { this.btnNode.x = posX + (location.x - this._prevX); this.btnNode.y = posY + (location.y - this._prevY); this._prevX = location.x; this._prevY = location.y; } }, _onTouchEnd (event) { if (!this._didMove) { this.onClicked(); } this._didMove = false; this._prevX = 0; this._prevY = 0; cc.tween(this.btnNode) .delay(1) .to(1, {opacity: 0}) .start(); } });