-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mousePressed() not firing on mobile on touch start #7195
Comments
Hi @eyaler, Thanks for reporting this! It looks like you're running into a common issue with
Workaround:You can use the let value = 0;
function setup() {
createCanvas(100, 100);
}
function draw() {
background(200);
fill(value);
square(25, 25, 50);
}
// Trigger when touch starts
function touchStarted() {
toggleColor();
}
// Trigger when mouse is pressed (for desktop)
function mousePressed() {
toggleColor();
}
function toggleColor() {
if (value === 0) {
value = 255;
} else {
value = 0;
}
} Why this happens:
By using Let me know if this works for your case! |
Thanks. I do find this quote from the docs to be confusing:
Some questions:
The bottom line is that I expect my pointer logic to work an with either mouse, trackpad or touchscreen. Would be nice to have this out of the box or have a streamlined way to do so.
|
Also linking this to this other related issue: #7260 |
p5.js doesn't seem to have any intention of fixing this bug... |
I don't think that's the case, the maintainers right now are deep in the middle of some refactor for 2.0 so it might take some time before any of us get a chance, so in the mean time if anyone else wants to take a crack at it is more than welcome! I think the first step, if possible, is to try to adhere to the documented API but with an implementation that fixes the current bugs without breaking the previously fixed ones again. this is definitely challenging and likely needs help testing on different devices, and a more systematic approach to tests so we avoid going in circles breaking prior behavior again. We haven't updated docs to reflect the current buggy situation because, if possible, this would be the route we take. That said, we're working against the browser here, so if we try that and keep running into issues, I think a possible step 2 is to change the API and no longer try to make touches and clicks with differently than the way they work in native APIs. that's more work for users, but at least is consistent with other JS touch handling, and would be simpler to maintain. |
I'm going to close this now that #7378 is merged, as 2.0 will now use the same pointer events API for desktop and mobile. |
Most appropriate sub-area of p5.js?
p5.js version
1.10.0 and 1.9.4
Web browser and version
chrome 128 and firefox 129
Operating system
android 12
Steps to reproduce this
On android the mousePressed() function does not trigger when the touch starts.
If I do a short tap - mousePressed() triggers on release
If I do a long tap or tap-and-drag - mousePressed() never triggers
I expect mousePressed() to be triggered in the same way touchStarted() would trigger (to be clear I don't have a touchStarted handler defined)
This prevents me from using mousePressed() to capture the mouse/touch location on pointer down.
Steps:
example 1 (using official example):
example 2 (custom code to isolate the issue):
Snippet:
The text was updated successfully, but these errors were encountered: