Skip to content

Commit 435435e

Browse files
committed
Handle touch
1 parent 2b7303b commit 435435e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

feature-phone.js

+28
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ canvas.addEventListener("mouseup", (e) => {
9494
.notifyInput(0, x, y);
9595
});
9696

97+
// Handle Touch Start on HTML Canvas
98+
canvas.addEventListener("touchstart", (e) => {
99+
// Notify Zig of Touch Start
100+
e.preventDefault();
101+
const touches = e.changedTouches;
102+
if (touches.length == 0) { return; }
103+
104+
const x = touches[0].pageX;
105+
const y = touches[0].pageY;
106+
console.log({touchstart: {x, y}});
107+
wasm.instance.exports
108+
.notifyInput(1, x, y);
109+
});
110+
111+
// Handle Touch End on HTML Canvas
112+
canvas.addEventListener("touchend", (e) => {
113+
// Notify Zig of Touch End
114+
e.preventDefault();
115+
const touches = e.changedTouches;
116+
if (touches.length == 0) { return; }
117+
118+
const x = touches[0].pageX;
119+
const y = touches[0].pageY;
120+
console.log({touchend: {x, y}});
121+
wasm.instance.exports
122+
.notifyInput(0, x, y);
123+
});
124+
97125
// Main Function
98126
function main() {
99127
console.log("main: start");

0 commit comments

Comments
 (0)