Commit 858319e4 authored by Li Mingzhe's avatar Li Mingzhe

fix: drag

parent 786dcc03
...@@ -49,7 +49,12 @@ cc.Class({ ...@@ -49,7 +49,12 @@ cc.Class({
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
onLoad () { onLoad () {
this.downFlag = false;
this.mask = this.node.getChildByName('Mask').getComponent(cc.Mask); this.mask = this.node.getChildByName('Mask').getComponent(cc.Mask);
this.node.on(cc.Node.EventType.MOUSE_DOWN, this.mouseDown, this);
this.node.on(cc.Node.EventType.MOUSE_MOVE, this.mouseMove, this);
this.node.on(cc.Node.EventType.MOUSE_UP, this.mouseUp, this);
this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart, this); this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this); this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this); this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
...@@ -74,23 +79,70 @@ cc.Class({ ...@@ -74,23 +79,70 @@ cc.Class({
// console.log(55555, this._id, able); // console.log(55555, this._id, able);
this.touchable = able; this.touchable = able;
}, },
mouseDown(e){
if (!this.touchable) {
return
}
this.downFlag = true;
this.scratch(e);
if (this.node.hasEventListener(cc.Node.EventType.TOUCH_START)) {
this.node.off(cc.Node.EventType.TOUCH_START, this.touchStart, this);
}
},
mouseMove(e){
if (!this.touchable) {
return
}
if (!this.downFlag) {
return;
}
this.scratch(e);
if (this.node.hasEventListener(cc.Node.EventType.TOUCH_MOVE)) {
this.node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
}
},
mouseUp(e) {
this.downFlag = false;
if (this.node.hasEventListener(cc.Node.EventType.TOUCH_END)) {
this.node.off(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
}
if (this.node.hasEventListener(cc.Node.EventType.TOUCH_CANCEL)) {
this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel, this);
}
},
touchStart(e){ touchStart(e){
if (!this.touchable) { if (!this.touchable) {
return return
} }
this.downFlag = true;
this.scratch(e); this.scratch(e);
if (this.node.hasEventListener(cc.Node.EventType.MOUSE_DOWN)) {
this.node.off(cc.Node.EventType.MOUSE_DOWN, this.mouseDown, this);
}
}, },
touchMove(e){ touchMove(e){
if (!this.touchable) { if (!this.touchable) {
return return
} }
this.scratch(e); this.scratch(e);
if (this.node.hasEventListener(cc.Node.EventType.MOUSE_MOVE)) {
this.node.off(cc.Node.EventType.MOUSE_MOVE, this.mouseMove, this);
}
}, },
touchEnd(e){ touchEnd(e){
this.downFlag = false;
// this.scratch(e); // this.scratch(e);
if (this.node.hasEventListener(cc.Node.EventType.MOUSE_UP)) {
this.node.off(cc.Node.EventType.MOUSE_UP, this.mouseUp, this);
}
}, },
touchCancel(e){ touchCancel(e){
this.downFlag = false;
// this.scratch(e); // this.scratch(e);
if (this.node.hasEventListener(cc.Node.EventType.MOUSE_UP)) {
this.node.off(cc.Node.EventType.MOUSE_UP, this.mouseUp, this);
}
}, },
initRectMaskPoints() { initRectMaskPoints() {
const rows = Math.floor(this.node.height / (this.touchScratchRadius * 2)); const rows = Math.floor(this.node.height / (this.touchScratchRadius * 2));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment