added touchscreen support

This commit is contained in:
Nathan DECHER 2020-03-26 10:47:22 +01:00
parent 1df62ff1fe
commit 6b7ff7e86d

View file

@ -108,4 +108,16 @@
else if(e.key=='ArrowRight') inputs.right=true;
});
window.addEventListener('touchstart', e => {
let x=e.touches[0].clientX/window.innerWidth-.5;
let y=e.touches[0].clientY/window.innerHeight-.5;
const angle=((Math.atan2(x, y)+2*Math.PI)%(2*Math.PI))/Math.PI;
let inputs=currentInputs;
if(angle>.25 && angle <.75) inputs.right=true;
else if(angle>.75 && angle<1.25) inputs.up=true;
else if(angle>1.25 && angle<1.75) inputs.left=true;
else inputs.down=true;
});
})();