I recently changed to LWJGL 3 because of an issue with my gamepad, but now I found a new problem.
import com.jme3.app.SimpleApplication;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.JoyAxisTrigger;
import com.jme3.input.controls.JoyButtonTrigger;
import com.jme3.system.AppSettings;
public class JoyTest extends SimpleApplication implements ActionListener {
public static void main(String... args) {
AppSettings settings = new AppSettings(true);
settings.setFullscreen(false);
settings.setUseJoysticks(true);
JoyTest app = new JoyTest();
app.setShowSettings(false);
app.setSettings(settings);
app.start();
}
private void initInputCommands() {
inputManager.addMapping("left", new JoyAxisTrigger(0, 0, true));
inputManager.addMapping("right", new JoyAxisTrigger(0, 0, false));
inputManager.addMapping("up", new JoyAxisTrigger(0, 1, true));
inputManager.addMapping("down", new JoyAxisTrigger(0, 1, false));
inputManager.addMapping("button A", new JoyButtonTrigger(0, 0));
inputManager.addListener(this, "left", "right", "up", "down"
// ,"button A"
);
}
@Override
public void simpleInitApp() {
initInputCommands();
}
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed) {
System.out.println("Pressed: " + name);
} else {
System.out.println("Released: " + name);
}
}
}
The code works as expected, the method onAction
is called once whenever a direction is “pressed” or “released” on the left stick. However, if I uncomment the line 29 ( , button A
), the code behaves strangely. It calls onAction
endlessly, no matter if the button is being pressed or not on the controller.