1 cc.Class({ 2 extends: cc.Component, 3 4 properties: { 5 }, 6 7 onLoad: function () { 8 this.startPos = cc.v2(0, 0); //开始位置 9 this.endPos = cc.v2(0, 0); //结束位置 10 11 this.node.on(cc.Node.EventType.TOUCH_START, function (event) { 12 this.startPos = cc.v2(event.getLocation().x, event.getLocation().y); 13 //获取点击的位置 14 cc.log("起始坐标点:x = " + event.getLocation().x + ", y = " + event.getLocation().y); 15 }, this); 16 17 this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) { 18 var delta = event.touch.getDelta(); 19 this.node.x += delta.x; 20 this.node.y += delta.y; 21 },this); 22 23 24 this.node.on(cc.Node.EventType.TOUCH_END, function (event) { 25 26 this.endPos = cc.v2(event.getLocation().x, event.getLocation().y); 27 cc.log("终点坐标点 x :" + event.getLocation().x + ", 终点坐标点 y :" + event.getLocation().y ); 28 29 let distance = this.startPos.sub(this.endPos).mag(); 30 cc.log("移动距离 :" + distance); 31 }, this); 32 33 }, 34 35 update: function (dt) { 36 37 }, 38 });