Skip to content

Commit 8ae6404

Browse files
committed
add touch support
1 parent 886dbb4 commit 8ae6404

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

02-Archery-Game/script.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ var lineSegment = {
1818
};
1919

2020
// bow rotation point
21-
// var pivot = {
22-
// x: 100,
23-
// y: 250
24-
// };
21+
var pivot = {
22+
x: 100,
23+
y: 250
24+
};
2525

2626
// 判断当前设备是否为触摸屏
2727
function isTouchDevice() {
@@ -36,19 +36,20 @@ function getScreenCenter() {
3636
};
3737
}
3838

39-
// 设置 pivot 点
40-
var pivot;
39+
// // 设置 pivot 点
40+
// var pivot;
41+
42+
// if (isTouchDevice()) {
43+
// // 如果是触摸屏,使用屏幕中心作为 pivot 点
44+
// pivot = getScreenCenter();
45+
// } else {
46+
// // 如果不是触摸屏,使用固定的 pivot 点
47+
// pivot = {
48+
// x: 100,
49+
// y: 250
50+
// };
51+
// }
4152

42-
if (isTouchDevice()) {
43-
// 如果是触摸屏,使用屏幕中心作为 pivot 点
44-
pivot = getScreenCenter();
45-
} else {
46-
// 如果不是触摸屏,使用固定的 pivot 点
47-
pivot = {
48-
x: 100,
49-
y: 250
50-
};
51-
}
5253

5354
aim({
5455
clientX: 320,
@@ -74,10 +75,11 @@ function draw(e) {
7475
// 禁止下拉刷新
7576
document.addEventListener('touchmove', function(event) {
7677
event.preventDefault(); // 阻止默认行为
78+
draw(event);
7779
}, { passive: false });
7880

7981
function aim(e) {
80-
82+
8183
// get mouse position in relation to svg position and scale
8284
var point = getMouseSVG(e);
8385
point.x = Math.min(point.x, pivot.x - 7);

0 commit comments

Comments
 (0)