Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

487
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda