| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- cc.Class({
- extends: cc.Component,
- properties: {
- // nodeArr:[cc.Node]
- },
- onLoad () {
- this.firstX = null;
- this.firsty = null;
- this.node.on(cc.Node.EventType.TOUCH_START,this.touchBegin,this);
- this.node.on(cc.Node.EventType.TOUCH_END,this.touchEnd,this);
- this.nodeArr = [];
- },
- touchBegin:function(event)
- {
- let location = event.getLocation();// 获取节点坐标
- this.firstX = location.x;
- this.firstY = location.y;
- },
- touchEnd:function(event)
- {
- let touchPoint = event.getLocation();
- let endX = this.firstX - touchPoint.x;
- let endY = this.firstY - touchPoint.y;
-
- if (Math.abs(endX) > Math.abs(endY)){
- //手势向左右
- //判断向左还是向右
- if (endX > 0){
- //向左函数
- // console.log('left');
- this.node.emit("gesture",{name:'left'});
- // this.dispatch('touchLeft');
- } else {
- //向右函数
- // console.log('right');
- this.node.emit("gesture",{name:'right'});
- }
- } else {
- //手势向上下
- //判断手势向上还是向下
- if (endY > 0){
- //向下函数
- // console.log('down');
- this.node.emit("gesture",{name:'down'});
- } else {
- //向上函数
- // console.log('up');
- this.node.emit("gesture",{name:'up'});
- }
- }
- }
- });
|