From 6ea4249ed90a75141d7704c2a8140a5f4a90d544 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 28 Aug 2020 16:17:24 +0200 Subject: [PATCH] Added touch support --- client/src/components/Game.vue | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/client/src/components/Game.vue b/client/src/components/Game.vue index e2ae49d..2e392bd 100644 --- a/client/src/components/Game.vue +++ b/client/src/components/Game.vue @@ -44,6 +44,7 @@ export default { this.canvas.width = window.innerWidth this.canvas.height = window.innerHeight this.canvas.addEventListener('mousemove', this.mouseEvent) + this.canvas.addEventListener('touchmove', this.touchEvent) this.renderTimer = setInterval(this.render, 1000 / 60) }, methods: { @@ -137,6 +138,16 @@ export default { this.mouse.x = event.clientX - rect.left this.mouse.y = event.clientY - rect.top + this.sendAngleUpdate() + }, + touchEvent (event) { + var rect = this.canvas.getBoundingClientRect() + this.mouse.x = event.touch[0].clientX - rect.left + this.mouse.y = event.touch[0].clientY - rect.top + + this.sendAngleUpdate() + }, + sendAngleUpdate () { var dx = this.mouse.x - this.canvas.width / 2 var dy = this.mouse.y - this.canvas.height / 2