From 734797915a3ed3fbb13ed6da081a03b6e9d8e619 Mon Sep 17 00:00:00 2001 From: Benjamin Schulte Date: Tue, 12 Jan 2021 18:07:21 +0100 Subject: [PATCH] Desktop: improve accuracy of canVibrate() and isVibrating() --- .../desktop/support/JamepadController.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gdx-controllers-desktop/src/main/java/com/badlogic/gdx/controllers/desktop/support/JamepadController.java b/gdx-controllers-desktop/src/main/java/com/badlogic/gdx/controllers/desktop/support/JamepadController.java index d4f3011..8104f35 100644 --- a/gdx-controllers-desktop/src/main/java/com/badlogic/gdx/controllers/desktop/support/JamepadController.java +++ b/gdx-controllers-desktop/src/main/java/com/badlogic/gdx/controllers/desktop/support/JamepadController.java @@ -34,6 +34,7 @@ public class JamepadController implements Controller { private final IntMap axisState = new IntMap<>(); private final String uuid; private boolean connected = true; + private boolean canVibrate = true; private long vibrationEndMs; public JamepadController(ControllerIndex controllerIndex) { @@ -158,7 +159,7 @@ private void initializeState() { @Override public boolean canVibrate() { - return true; + return canVibrate; } @Override @@ -169,8 +170,12 @@ public boolean isVibrating() { @Override public void startVibration(int duration, float strength) { try { - controllerIndex.doVibration(strength, strength, duration); - vibrationEndMs = TimeUtils.millis() + duration; + if (controllerIndex.doVibration(strength, strength, duration)) { + vibrationEndMs = TimeUtils.millis() + duration; + canVibrate = true; + } else { + canVibrate = false; + } } catch (ControllerUnpluggedException e) { setDisconnected(); }