added touchscreen support

main
Codinget 5 years ago
parent c9c9e20fdb
commit c7352e0e2a
  1. 12
      src/js/main.js

@ -108,4 +108,16 @@
else if(e.key=='ArrowRight') inputs.right=true; 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;
});
})(); })();

Loading…
Cancel
Save