fix for touches

This commit is contained in:
Pavel Dobryakov
2017-08-26 14:12:30 +03:00
parent 6d8778ad76
commit fe49079f05
2 changed files with 20 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<head>
<style>
html, body {

View File

@@ -1,5 +1,7 @@
'use strict';
window.scrollTo(0, 1);
const canvas = document.getElementsByTagName('canvas')[0];
const params = { alpha: false, depth: false, stencil: false, antialias: false };
@@ -519,30 +521,34 @@ canvas.addEventListener('mousemove', (e) => {
canvas.addEventListener('touchmove', (e) => {
e.preventDefault();
const touches = e.targetTouches;
for (let i = 0; i < e.touches.length; i++) {
if (i >= pointers.length) {
pointers.push(new pointerPrototype());
}
let pointer = pointers[i];
pointer.moved = pointer.down;
pointer.dx = (e.touches[i].pageX - pointer.x) * 10.0;
pointer.dy = (e.touches[i].pageY - pointer.y) * 10.0;
pointer.x = e.touches[i].pageX;
pointer.y = e.touches[i].pageY;
pointer.dx = (touches[i].pageX - pointer.x) * 10.0;
pointer.dy = (touches[i].pageY - pointer.y) * 10.0;
pointer.x = touches[i].pageX;
pointer.y = touches[i].pageY;
}
}, false);
canvas.addEventListener('mousedown', () => {
pointers[0].dowm = true;
pointers[0].color = [Math.random() + 0.2, Math.random() + 0.2, Math.random() + 0.2];
});
canvas.addEventListener('mousedown', onPointerDown);
canvas.addEventListener('touchstart', onPointerDown);
window.addEventListener('mouseup', onPointerUp);
window.addEventListener('touchend', onPointerUp);
function onPointerDown () {
canvas.addEventListener('touchstart', () => {
for (let i = 0; i < pointers.length; i++) {
pointers[i].down = true;
pointers[i].color = [Math.random() + 0.2, Math.random() + 0.2, Math.random() + 0.2];
}
}
});
window.addEventListener('mouseup', onPointerUp);
window.addEventListener('touchend', onPointerUp);
function onPointerUp () {
for (let i = 0; i < pointers.length; i++) {