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

126
Views
Mobile devices touch event is not being triggered as many times as I clicked

I have developed a candy-crush like game using react and canvas, but it is not working as expected on mobile devices. I have these listeners:

if (isMobile) {
  canvas.addEventListener('touchstart', onMouseDown);
  canvas.addEventListener('touchend', onMouseUp);
} else {
  canvas.addEventListener('mousemove', onMouseMove);
  canvas.addEventListener('mousedown', onMouseDown);
  canvas.addEventListener('mouseup', onMouseUp);
  canvas.addEventListener('mouseout', onMouseOut);
}

and it works perfectly on desktop. But on mobile devices listener is not being triggered right away after I clicked second time. For example if I want to swap tiles I have to click on any tile and wait for like 1 second to click another one so swap function was triggered. If I click the second tile straight after I've clicked the first one: listener will not be triggered. And it works the same way even with simple console.log function. If I've clicked N times, I will see far less logs in the console.

Here is my FPS control function:

const updateFps = (dt) => {
  if (fpstime > 10) {
    fps = Math.round(framecount / fpstime);

    fpstime = 0;
    framecount = 0;
  }

  fpstime += dt;
  framecount += 1;
};

and here is my animation function:

const main = (tframe) => {
  requestAnimationFrame(main);

  update(tframe);
  render();
};

Is there any way to improve usability on mobile devices? Can it somehow be connected with rerenders of fps limitations?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So, I found out that somehow only on ios devices DOM and scripts are being blocked after first touch has triggered the listener. So after few hours of suffering a casual e.preventDefault() did the job. So simply use it in your listener :)

about 4 years ago · Juan Pablo Isaza Report
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!