Action button: only true once per press
- by Sidar
I'm using SFML2.0 and am trying to make a wrapper class for my controller/joystick.
I read all the input data from my controller and send it off to my controllable object.
I want to have two types of buttons per button press, one that is continues(true false state ) and one that is an action and is set to false after the next frame update.
Here is an example of how I set my button A to true or false with the SFML api.
Whereas data is my struct of buttons, and A holds my true/false state every update.
data.A = sf::Joystick::isButtonPressed(i,st::input::A);
But I've also added "data.actionA" which represents the one time action state.
Basically what I want is for actionA to be set false after the update its been set to true. I'm trying to keep track of the previous state. But I seem to fall into this loop where it toggles between true and false every update.
Anyone an idea?
Edit:
Since I can't answer my own question yet here is my solution:
data.actionA = data.A = sf::Joystick::isButtonPressed(i,st::input::A);
if(prev.A) data.actionA = false;
First I always set the actionA to the value of the button state. Then I check if the previous state of A is true. If so we negate the value.