Fix: prevent gamepad buttons from sending bogus down events on init #7126
+4
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please do not update the README or Change Log, we will do this when we merge your PR.
This PR (delete as applicable)
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 officialpressed
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.