TouchStarted() problem with mobile

Hello, I have a sketch where I use the touchStarted() function, and it does not work with a mobile device (i.e.: nothing happen when I’m touching the screen).

NOTE: when I run the same script with a compute, it works well - it’s just the mobile devices that seems to have a problem.

Any proposed workaround for that ?

Thanks !

Fred.

HI @FredGuillot,

did you notice that ?

Browsers may have different default behaviors attached to various touch events. To prevent any default behavior for this event, add “return false” to the end of the method

see touchStarted:

Cheers
— mnse

Thanks for your fast reply ! Yes, I just saw thing this morning and I try that but it still not working …

Could it be because I have both a mousePressed and a touchStarted statements in my sketch (my goal with this is to handle both computer and mobile experience)?

Also, I tried to switch mouseX/mouseY by touchX/ touchY in the script with no success …

Hi @FredGuillot,

The touchStarted() function is called once after every time a touch is registered. If no touchStarted() function is defined, the mousePressed() function will be called instead if it is defined.

As suggested here you can remove the touchStarted and just use mousePressed for both …
Afterwards use mouseX and mouseY to get the location. On my mobile it works …

Cheers
— mnse

1 Like

Hey, it was the issue ! It’s working now ! Thank you so much for your great help !

Cheers !