Added touch support

This commit is contained in:
Thomas
2020-08-28 16:17:24 +02:00
parent 8add12d4c3
commit 6ea4249ed9

View File

@@ -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