GWAK
November 16, 2023, 1:06am
1
p5 ‘mousePressed()’ function error
hello. Nice to meet you.
Please refer to the video.
https://www.youtube.com/shorts/n2i0YRm-yJY
WEB was implemented through ‘p5’.
Image change was performed through ‘mousePressed()’.
On PC, ‘mousePressed()’ is called once per touch.
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?
jafal
November 16, 2023, 3:46am
2
Hi
Try this
let mouseCounter = 0;
function mousePressed() {
mouseCounter++;
return false;
}
opened 03:36PM - 18 Feb 17 UTC
closed 11:10PM - 14 Mar 17 UTC
Everything was working fine for a while with a program I have until Chrome was r… ecently updated to v56. On the desktop, it still seems to work fine, but if you're on mobile or use the emulator in the browser, there seems to be an issue with mousePressed.
When I press anywhere on the canvas, I get the following in the console:
Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/5093566007214080
Uncaught TypeError: Cannot read property 'clientX' of undefined
at d (p5.min.js:5)
at e._updateNextMouseCoords (p5.min.js:5)
at e._ontouchend (p5.min.js:6)
I do return false at the end of the mousePressed function. If I comment that out, I no longer receive the warning about preventDefault but I still get the Uncaught TypeError.
2 Likes
GWAK
November 16, 2023, 7:20am
3
@jafal
Hello. how are you?
Thank you for quick response. Thank you for caring me.
1 Like
jafal
November 16, 2023, 5:55pm
4
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