File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -316,21 +316,20 @@ function keyRight() {// pressed right arrow key
316
316
}
317
317
//增加一个触摸屏幕事件,让Paddle水平移动距离和触摸点水平移动距离一致
318
318
var touchXstart = null ;
319
+ var previousPosition = canvas . width / 2 - paddle . w / 2 ;
319
320
function actionStart ( e ) {
320
321
e . preventDefault ( ) ;
321
322
//判断是鼠标左键点击还是触摸
322
-
323
323
if ( e . touches && touchXstart == null ) { //如果是触摸 touchXstart等于第一个touch点的x坐标
324
324
touchXstart = e . touches [ 0 ] . pageX ;
325
325
} else { //如果是鼠标 touchXstart等于鼠标的x坐标
326
326
touchXstart = e . pageX ;
327
327
}
328
-
329
-
330
328
}
331
329
function actionEnd ( e ) {
332
330
e . preventDefault ( ) ;
333
331
touchXstart = null ;
332
+ previousPosition = paddle . x ;
334
333
}
335
334
function actionMove ( e ) {
336
335
//e.preventDefault();
@@ -343,10 +342,9 @@ function actionMove(e){
343
342
dist = e . pageX - touchXstart ;
344
343
}
345
344
// dist 按照画布的放大比例缩放
346
- var canvasS = document . getElementById ( "canvas" ) ;
347
- dist = dist / canvas . width * canvasS . clientWidth / 2 ;
345
+
348
346
349
- paddle . x = paddle . x + dist ;
347
+ paddle . x = previousPosition + dist ;
350
348
if ( paddle . x + paddle . w > canvas . width ) paddle . x = canvas . width - paddle . w ;
351
349
if ( paddle . x < 0 ) paddle . x = 0 ;
352
350
}
You can’t perform that action at this time.
0 commit comments