1
General / How can you toggle something with pressing a key?
« on: March 13, 2014, 03:23:16 am »
I looked in the resources, I couldn't find any information on how to do this. So I'm trying to figure out how to set "int a" from 0 to 1 by pressing down a key. For example:
So the problem here is that a = 1 as long as the key is pressed down, but once I release it, it goes back to equaling 0. I want to press it, and have it stay 1(not from releasing, from pressing once). Any solutions? Thanks.
EDIT: Forgot to mention this is in while (window.isOpen()){}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)){
a = 1; //int a was already declared
}
a = 1; //int a was already declared
}
So the problem here is that a = 1 as long as the key is pressed down, but once I release it, it goes back to equaling 0. I want to press it, and have it stay 1(not from releasing, from pressing once). Any solutions? Thanks.
EDIT: Forgot to mention this is in while (window.isOpen()){}