Browse Source

多点触控

huangxiaojing 3 years ago
parent
commit
f3923a720f
1 changed files with 9 additions and 6 deletions
  1. 9 6
      screenAndroid/WXdraw.js

+ 9 - 6
screenAndroid/WXdraw.js

@@ -179,17 +179,17 @@ var draw_graph = function (graphType, obj) {
       "right": "-4rem"
     })
     var touchfor = e.originalEvent.changedTouches[0]; //for 的手指数组
-    ongoingTouches.push(touchfor);
     var acrossWidthX = touchfor.pageY * (videoHeight / voheight);
     var acrossHeightY = videoWidth - touchfor.pageX * (videoWidth / vowidth);
     var verticalWidthX = touchfor.pageX * (videoWidth / vowidth);
     var verticalHeightY = touchfor.pageY * (videoHeight / voheight);
     //是否横屏
     var ping = resolving == 0 ?
-      { "data": { "action": 0, "count": ongoingTouches.length, "id": touchfor.identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
-      { "data": { "action": 0, "count": ongoingTouches.length, "id": touchfor.identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
-      console.log(ping);
+    { "data": { "action": 0, "count": ongoingTouches.length, "id": touchfor.identifier, "x": acrossWidthX.toFixed(2), "y": acrossHeightY.toFixed(2) }, "type": "event" } :
+    { "data": { "action": 0, "count": ongoingTouches.length, "id": touchfor.identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
+    console.log(ping);
     wsss.send(JSON.stringify(ping));
+    ongoingTouches.push(touchfor);
     canDraw = true;
   };
 
@@ -206,7 +206,11 @@ var draw_graph = function (graphType, obj) {
       { "data": { "action": 1, "count": ongoingTouches.length, "id": touchfor.identifier, "x": verticalWidthX.toFixed(2), "y": verticalHeightY.toFixed(2) }, "type": "event" };
       console.log(ping);
     wsss.send(JSON.stringify(ping));
-    ongoingTouches.splice(touchfor.identifier, 1);
+    ongoingTouches.forEach(function(item, index) {
+      if (item.identifier === touchfor.identifier) {
+        ongoingTouches.splice(index, 1)
+      }
+    });
     canDraw = false;
   };
 
@@ -217,7 +221,6 @@ var draw_graph = function (graphType, obj) {
 
   // 鼠标移动
   var touchmove = function (e) {
-    e = e || window.event;
     var touchfor = e.originalEvent.changedTouches[0]; //for 的手指数组
     var acrossWidthX = touchfor.pageY * (videoHeight / voheight);
     var acrossHeightY = videoWidth - touchfor.pageX * (videoWidth / vowidth);