@@ -346,7 +346,7 @@ function actionStart(e) {
346
346
//判断是鼠标左键点击还是触摸
347
347
var leftPt = { pageX : canvas . width , pageY : 0 } , rightPt = { pageX : 0 , pageY : 0 } ;
348
348
349
- if ( e . touches ) { //如果是触摸
349
+ if ( e . touches && e . touches . length > 1 ) { //如果是触摸
350
350
e . touches . forEach ( element => { //记录左半边,最左边的点
351
351
if ( element . pageX - canvas . offsetLeft < canvas . width / 2 ) {
352
352
leftPt = element . pageX < leftPt . pageX ? element : leftPt ;
@@ -357,7 +357,13 @@ function actionStart(e) {
357
357
if ( touchYstartLeft == null ) { touchYstartLeft = leftPt . pageY ; }
358
358
if ( touchYstartRight == null ) { touchYstartRight = rightPt . pageY ; }
359
359
return ;
360
- } else { //如果是鼠标 touchXstart等于鼠标的x坐标
360
+ } else if ( e . touches && e . touches . length == 1 ) { //如果是单点触摸
361
+ if ( e . touches [ 0 ] . pageX - canvas . offsetLeft < canvas . width / 2 ) {
362
+ if ( touchYstartLeft == null ) { touchYstartLeft = e . touches [ 0 ] . pageY ; }
363
+ } else {
364
+ if ( touchYstartRight == null ) { touchYstartRight = e . touches [ 0 ] . pageY ; }
365
+ }
366
+ } else { //如果是鼠标 touchXstart等于鼠标的x坐标
361
367
if ( e . pageX - canvas . offsetLeft < canvas . width / 2 ) {
362
368
if ( touchYstartLeft == null ) { touchYstartLeft = e . pageY ; }
363
369
} else {
@@ -384,7 +390,7 @@ function actionMove(e) {
384
390
//e.preventDefault();
385
391
var distLeft , distRight , leftPt , rightPt ;
386
392
//判断是鼠标左键点击还是触摸
387
- if ( e . touches ) {
393
+ if ( e . touches && e . touches . length > 1 ) { //如果是触摸
388
394
e . touches . forEach ( element => {
389
395
if ( element . pageX - canvas . offsetLeft < canvas . width / 2 ) {
390
396
leftPt = element . pageX < leftPt . pageX ? element : leftPt ;
@@ -405,7 +411,24 @@ function actionMove(e) {
405
411
if ( rightPaddleY < 0 ) rightPaddleY = 0 ;
406
412
}
407
413
408
- } else { //如果是鼠标 dist等于鼠标的x坐标x相对touchXstart的移动距离
414
+ } else if ( e . touches && e . touches . length == 1 ) { //如果是单点触摸
415
+ if ( e . touches [ 0 ] . pageX - canvas . offsetLeft < canvas . width / 2 ) {
416
+ if ( touchYstartLeft != null ) {
417
+ distLeft = e . touches [ 0 ] . pageY - touchYstartLeft ;
418
+ leftPaddleY = previousPositionLeft + distLeft ;
419
+ if ( leftPaddleY + paddleHeight > canvas . height ) leftPaddleY = canvas . height - paddleHeight ;
420
+ if ( leftPaddleY < 0 ) leftPaddleY = 0 ;
421
+ }
422
+ } else {
423
+ if ( touchYstartRight != null ) {
424
+ distRight = e . touches [ 0 ] . pageY - touchYstartRight ;
425
+ rightPaddleY = previousPositionRight + distRight ;
426
+ if ( rightPaddleY + paddleHeight > canvas . height ) rightPaddleY = canvas . height - paddleHeight ;
427
+ if ( rightPaddleY < 0 ) rightPaddleY = 0 ;
428
+ }
429
+ }
430
+
431
+ } else { //如果是鼠标 dist等于鼠标的x坐标x相对touchXstart的移动距离
409
432
if ( e . pageX - canvas . offsetLeft < canvas . width / 2 ) {
410
433
if ( touchYstartLeft != null ) {
411
434
distLeft = e . pageY - touchYstartLeft ;
0 commit comments