Skip to content

Commit

Permalink
Fix firstPressed functions in FlxGamepad (#2728)
Browse files Browse the repository at this point in the history
* `firstPressedRawID` now returns the first button that's pressed instead of the first button that's released
* `firstPressedID`, `firstJustPressedID` and `firstJustReleasedID` now properly work on XInput and Logitech controllers (before, if no buttons were found, it would return `GUIDE` as opposed to `NONE`)
  • Loading branch information
Starmapo authored Feb 13, 2023
1 parent 16f8ca1 commit b5556c4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions flixel/input/gamepad/FlxGamepad.hx
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,11 @@ class FlxGamepad implements IFlxDestroyable
*/
public inline function firstPressedID():FlxGamepadInputID
{
return mapping.getID(firstPressedRawID());
var id = firstPressedRawID();
if (id < 0)
return id;

return mapping.getID(id);
}

/**
Expand All @@ -460,7 +464,7 @@ class FlxGamepad implements IFlxDestroyable
{
for (button in buttons)
{
if (button != null && button.released)
if (button != null && button.pressed)
{
return button.ID;
}
Expand All @@ -474,7 +478,11 @@ class FlxGamepad implements IFlxDestroyable
*/
public inline function firstJustPressedID():FlxGamepadInputID
{
return mapping.getID(firstJustPressedRawID());
var id = firstJustPressedRawID();
if (id < 0)
return id;

return mapping.getID(id);
}

/**
Expand All @@ -499,7 +507,11 @@ class FlxGamepad implements IFlxDestroyable
*/
public inline function firstJustReleasedID():FlxGamepadInputID
{
return mapping.getID(firstJustReleasedRawID());
var id = firstJustReleasedRawID();
if (id < 0)
return id;

return mapping.getID(id);
}

/**
Expand Down

0 comments on commit b5556c4

Please sign in to comment.