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

rightButtonDown() Not Working #4348

Closed
BobtheUltimateProgrammer opened this issue Feb 7, 2019 · 5 comments
Closed

rightButtonDown() Not Working #4348

BobtheUltimateProgrammer opened this issue Feb 7, 2019 · 5 comments

Comments

@BobtheUltimateProgrammer

OS: Windows 10
Browser: Google Chrome

The following code worked on Phaser 3.15 but as soon as I upgraded to 3.16 the following code does not trigger any more on right click.

this.input.on("pointerup",function(e) {
           if (e.rightButtonDown()) {
           alert(“I have been right clicked!”);

           }
} 

I investigated further and found out that right clicks in 3.16 actually trigger the following code instead.

this.input.on("pointerup",function(e) {
            if (e.noButtonDown()) {
                  alert(“This triggers for right clicks in Phaser 3.16! :(”);

            }
} 

Note: the same behavior applies to the scroll wheel (middle mouse button) - when I press down on the scroll wheel button, noButtonDown() is true while middleButtonDown() is false.

Am I am doing anything wrong or did something change in the new update? I followed the API Documentstion and these methods are still there. Any help is appreciated.

@photonstorm
Copy link
Collaborator

What happens for you in this example: http://labs.phaser.io/view.html?src=src%5Cinput%5Cpointer%5Cpointer%20buttons.js ?

If I press the left button and drag I get a yellow rectangle. If I press the right button I get a green one. If I press them both I get an aqua colored one.

Looking at your code I can see you are using pointerup. I believe the issue is that in 3.15 rightButtonDown etc were giving completely wrong results. I updated the docs for them to clarify what they do: "Checks to see if the X button is being held down on this Pointer". The key here is 'being held down right now'. In 3.15 it actually returned a historical value - if you checked rightButtonDown at any point, for example, it was always true if you pressed the right button at least once! because the buttons weren't reset in the up handler.

    this.input.on('pointerup', function (pointer) {

        console.log('up - left:', pointer.leftButtonDown(), 'right:', pointer.rightButtonDown());

    });

With the above, if I hold down BOTH buttons, then release just the left one, it will log 'false' for the left button being down, because it's not as I just released it, but 'true' for the right button being down, because I'm still holding it. They're actually working as I always intended them to now, they were just bugged before. You can finally use them safely in update loops, for example.

I think what you're trying to do is figure out which button was released, yes? Which in my mind calls for a different method. You can get the button that was released from the actual DOM event (so pointer.event.button in your handler). The following works:

    this.input.on('pointerup', function (pointer) {

        if (pointer.event.button === 0)
        {
            console.log('Left button released');
        }
        else if (pointer.event.button === 1)
        {
            console.log('Middle button released');
        }
        else if (pointer.event.button === 2)
        {
            console.log('Right button released');
        }

    });

But note that button IDs can be reassigned (left-handed devices, for example, can flip the button orders). It's probably safer to check the negative state of rightButtonDown than it is the above, but it definitely works. Hope that makes it a bit clearer.

@BigZaphod
Copy link
Contributor

After upgrading, I have this same problem too - my code is assuming rightButtonDown() still returns true in the pointerup event. I wonder how pervasive this pattern is.

@photonstorm
Copy link
Collaborator

Not really sure, but it needs to be changed, because even logically the method names (rightButtonDOWN, etc) don't actually make sense to be polled in an up event handler.

I think what needs to be offered are rightButtonReleased methods, or something similar.

@BobtheUltimateProgrammer
Copy link
Author

Hi,
Is there any update on whether something like rightButtonReleased will be implemented in the new Phaser update or should I stick to the native event buttons value? Thanks for your hard work.

@photonstorm
Copy link
Collaborator

Thank you for submitting this feature request. We have implemented this and the feature has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

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

No branches or pull requests

3 participants