Skip to content

Commit

Permalink
Retrieve gamepads by ID instead of index.
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen-wilke committed Dec 5, 2021
1 parent 52d100c commit c31fffd
Showing 1 changed file with 6 additions and 5 deletions.
Expand Up @@ -72,13 +72,14 @@ public void setRotateWithRightStick(boolean rotateWithRightStick) {
}

private void retrieveGamepadValues() {
final Gamepad gamepad = Input.gamepads().getById(this.gamepadId);
if (this.gamepadId == -1
|| this.gamepadId != -1 && Input.gamepads().getById(this.gamepadId) == null) {
|| this.gamepadId != -1 && gamepad == null) {
return;
}

final float x = Input.gamepads().get(this.gamepadId).getPollData(Gamepad.Axis.X);
final float y = Input.gamepads().get(this.gamepadId).getPollData(Gamepad.Axis.Y);
final float x = gamepad.getPollData(Gamepad.Axis.X);
final float y = gamepad.getPollData(Gamepad.Axis.Y);

if (Math.abs(x) > this.gamepadDeadzone) {
this.setDx(x);
Expand All @@ -89,8 +90,8 @@ private void retrieveGamepadValues() {
}

if (this.isRotateWithRightStick()) {
final float rightX = Input.gamepads().get(this.gamepadId).getPollData(Gamepad.Axis.RX);
final float rightY = Input.gamepads().get(this.gamepadId).getPollData(Gamepad.Axis.RY);
final float rightX = gamepad.getPollData(Gamepad.Axis.RX);
final float rightY = gamepad.getPollData(Gamepad.Axis.RY);
float targetX = 0;
float targetY = 0;
if (Math.abs(rightX) > this.gamepadRightStick) {
Expand Down

0 comments on commit c31fffd

Please sign in to comment.