Skip to content
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

bug: touchend event problem. #37

Closed
akira-cn opened this issue Aug 16, 2022 · 3 comments
Closed

bug: touchend event problem. #37

akira-cn opened this issue Aug 16, 2022 · 3 comments

Comments

@akira-cn
Copy link

The touchend event seems to be cancelable on mobile phones.

So the following code will prevent the page focus back sometime.

// try to enable touch mouse
if (isTouchDevice)
{
    // handle all touch events the same way
    let wasTouching, hadTouchInput;
    ontouchstart = ontouchmove = ontouchend = (e)=>
    {
        e.button = 0; // all touches are left click

        // check if touching and pass to mouse events
        const touching = e.touches.length;
        if (touching)
        {
            hadTouchInput || zzfx(0, hadTouchInput=1) ; // fix mobile audio, force it to play a sound the first time

            // set event pos and pass it along
            e.x = e.touches[0].clientX;
            e.y = e.touches[0].clientY;
            wasTouching ? onmousemove(e) : onmousedown(e);
        }
        else if (wasTouching)
            onmouseup(e);

        // set was touching
        wasTouching = touching;

        // prevent normal mouse events from being called
        return !e.cancelable; // 💥 touchend return false
    }
}
@akira-cn
Copy link
Author

Maybe should not clearInput when touch devices lose focus?

function inputUpdate {
    // clear input when lost focus (prevent stuck keys)
    isTouchDevice || document.hasFocus() || clearInput();

    // update mouse world space position
    mousePos = screenToWorld(mousePosScreen);

    // update gamepads if enabled
    gamepadsUpdate();
}

@KilledByAPixel
Copy link
Owner

Ok, I will look into it. Which phone do you know is having the problem?

The input needs to be cleared on focus lost to prevent keys from getting stuck. Do you think that is related?

@KilledByAPixel
Copy link
Owner

fixed! it now returns true from the on touch events. this fixes a bunch of problems we were seeing on mobile devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants