I couldnt find a method for on button release. Im using this so the user can hold down a button and it wont register it XX amount of times due to the refresh rate of the event loop. Thanks.
What are you using? LWJGL, etc…?
Oh sorry, im using the newest build of JInput.
A way to do it:
Have a boolean buttonPressed which you set to true if the button is pressed.
If the boolean changes from true to false you know the user released the button.
But if i say if buttonPressed == false, that would be all the time that it isnt pressed not just after it is pressed. Thanks though
boolean lastTimeButtonPressed = buttonPressed;
buttonPressed = checkIfButtonIsPressed();
if(lastTimeButtonPressed && !buttonPressed) {
System.out.println("The button has been released");
}
Ok thanks but you would have to set buttonPressed to false in that otherwise it would keep going.
boolean lastTimeButtonPressed = buttonPressed;
buttonPressed = checkIfButtonIsPressed();
if(lastTimeButtonPressed && !buttonPressed) {
System.out.println("The button has been released");
buttonPressed = false;
}
No, buttonPressed would already be false or it couldn’t get through the if statement.
boolean buttonPressed = false;
boolean lastButtonPressed = false;
In update method
buttonPressed = checkIfButtonPressed();
if(lastButtonPressed && !buttonPressed){
System.out.println("Button Released");
}
lastButtonPressed = buttonPressed
sorry i meant to put lastbuttonpressed should be false
and also can someone help explain why i get different results for these thanks:
This works:
if (Controllers.isCirclePressed() == true) {circlePressed = true;}
if (Controllers.isCirclePressed() == false && circlePressed == true)
{
if (jAutonomyBox.isSelected()) {jAutonomyBox.setSelected(false);}
else {jAutonomyBox.setSelected(true);}
circlePressed = false;
}
but if i use
circlePressed = Controllers.isCirclePressed();
instead of if(Controllers.isCirclePressed() == true)… it never gets called.