P5 'mousePressed()' function error

p5 ‘mousePressed()’ function error

hello. Nice to meet you.
Please refer to the video.

https://www.youtube.com/shorts/n2i0YRm-yJY

  1. WEB was implemented through ‘p5’.
  2. Image change was performed through ‘mousePressed()’.
  3. On PC, ‘mousePressed()’ is called once per touch.
  4. On smartphones, ‘mousePressed()’ is called multiple times with a single touch.

What’s wrong with smartphones? Is there any solution?

As of now, I have implemented it as follows.

var SAFE_PRESS = 0;
function mousePressed() {
if(SAFE_PRESS < millis()){
SAFE_PRESS = millis() + 1000;
}
}

Can you tell me a good solution or cause other than the above?

Hi
Try this

let mouseCounter = 0;
function mousePressed() {
    mouseCounter++;
    return false;
}

2 Likes

@jafal

Hello. how are you?

Thank you for quick response. Thank you for caring me.

1 Like

Hi
I am fine what’s about you hope you fine too

Here is the p5.js mouse issue for touch devices from the link I provided

Please be advised: per the p5 reference page, that some browsers have default behavior for mousePressed() functions. “Browsers may have different default behaviors attached to various mouse events. To prevent any default behavior for this event, add return false to the end of the method.” JUST DO IT!

Note when you remove this line
return false;
Counting won’t be stable

1 Like