Skip to content

Fix: prevent gamepad buttons from sending bogus down events on init #7126

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cryonautlex
Copy link

Please do not update the README or Change Log, we will do this when we merge your PR.

This PR (delete as applicable)

  • Fixes a bug

Describe the changes below:

Phaser is always initializing Gamepad buttons as not being pressed. This creates a problem when reading gamepad inputs in one scene, which starts another, and then reading gamepad inputs in the second scene. If the player holds the button down for a tiny, tiny bit in the first scene, the second scene sees a bogus down event.

The fix introduces a new, boolean parameter to gamepad Button's constructor, isPressed. When gamepad is initializing its buttons, it checks the current value for the button. If it's greater or equal to 0.5, Gamepad considers the Button pressed and passes true for this parameter. Otherwise, it passes false. Button then uses the isPressed parameter to initialize its official pressed property. By initializing with the current pressed state of the gamepad Button, the fix eliminates the bogus event at scene start.

This Phaselet tests for the bug. Grab a gamepad and follow the directions.

@cryonautlex
Copy link
Author

I used 0.5, because threshold is not available at time of Button construction.

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

Successfully merging this pull request may close these issues.

1 participant