How to not need double click

I make games on itch.io but when i test my games on mobile i need to doubleclick to click something for some reason but on computer while when i test on computer it only needs one click and i only want to be able to click once

You should try using:

this._mouseState

Here’s what this._mouseState is equal to and when:

this.mouseState /// Mobile /// Computer
“out” | If last clicked object
is outside clip
| If cursor isn’t
over clip
“over” | If last clicked object
is clip
| If cursor is
over clip
“down” | If finger is still over
clip
| If cursor is
down on clip

Now if you want click to work on mobile, you’ll want to see when this._mouseState is “down,” and if mouse is down (for mobile or computer), then wait until mouse isn’t down to run the click code.

Another method you can try would be to add this code to a mouseenter script while keeping the old mouseclick script without changing it:

this.runScript("mouseclick")

This fixes the mobile problem, however, it’d make it harder to click buttons on non-touch devices. I’d only recommend this method if you plan to make a mobile-only project.

2 Likes

however, it’d make it harder to click buttons on non-touch devices.

Maybe you can check if the device is a mobile device/PC then either pick the touch or click depending on the device, right?

1 Like

That is a good idea, I just looked online and found here a good function for detecting whether or not a user is on touch screen:

function isTouchDevice() {
  return (('ontouchstart' in window) ||
     (navigator.maxTouchPoints > 0) ||
     (navigator.msMaxTouchPoints > 0));
}

I already tried it on a mobile device and on my computer, it seems to work well

1 Like