Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

481
Views
Evento de fin de toque: obtener el toque que realmente terminó si hay más de un toque

Estoy escribiendo un script de movimiento móvil para una aplicación de tres JS, en el que si hace clic en la parte superior de la pantalla, gira la cámara y en la parte inferior mueve el personaje. Esto funciona perfectamente si está usando solo un toque, pero tan pronto como uso el segundo toque, aparece un problema: parece que no puedo encontrar una manera de usar el evento "toque final" SOLAMENTE para el segundo toque. Intenté usar ev.touches[1] o ev.touches[0] pero parece que no pasa nada. Realmente necesito que el dispositivo discrimine el toque que realmente terminó, si fue el primero presionado o el segundo.

Este es el codigo...

 var originTouch; var secondTouch; var newTouch; var previousTouch; document.body.addEventListener('touchstart', (ev) => { originTouch = ev.touches[0]; secondTouch = ev.touches[1]; console.log(originTouch); console.log(secondTouch); }) document.body.addEventListener('touchmove', (ev) => { if (ev.touches[0]) { if (ev.touches[0].clientY > window.innerHeight / 2) { var deltaY = originTouch.clientY - ev.touches[0].clientY; var deltaX = originTouch.clientX - ev.touches[0].clientX; if (deltaY > 0) { isGoingForward = true; isGoingBackward = false;} if (deltaY < 0) { isGoingBackward = true; isGoingForward = false;} if (deltaX < 0) { isGoingRight = true; isGoingLeft = false;} if (deltaX > 0) { isGoingLeft = true; isGoingRight = false;} } else { if (previousTouch) { var movementX = ev.touches[0].pageX - previousTouch.pageX; var movementY = ev.touches[0].pageY - previousTouch.pageY; camerina.rotation.y += movementX / 400; camerina.rotation.x += movementY / 400; } previousTouch = ev.touches[0]; } } if (ev.touches[1]) { if (ev.touches[1].clientY < window.innerHeight / 2) { if (newTouch) { var movementX = ev.touches[1].pageX - newTouch.pageX; var movementY = ev.touches[1].pageY - newTouch.pageY; camerina.rotation.y += movementX / 400; camerina.rotation.x += movementY / 400; } newTouch = ev.touches[1]; } } }) document.body.addEventListener('touchend', (ev) => { //this is, of course, ending every touch when the second touch is released. //but if I use --if (ev.touches[0] or [1])-- nothing happens. //It feels like I'm not getting a way to find which is the touch that actually ended. //this has to end only if the first touch ended, isGoingForward = false; isGoingBackward = false; isGoingLeft = false; isGoingRight = false; previousTouch = null; originTouch = null; //this has to end only if the second touch ended. newTouch = null; })
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!