Hello, I've been using SFML for a little while and I decided to create a DDR-like game with it.
The problem I have is, what is the best way to detect when a key has been pressed, and only execute the code which should be executed when the key has been pressed once?
The problem I have is that as long as the key is down, the game keeps executing the input code. (Basically to set the scale of a sprite to 0.5, otherwise it should go back up to 1). However the sprite always seems to stay at 0.5 when the key is held down, I want it to go to 0.5 when the key is first pressed and then return to 1.0.
Here is the code I'm using:
int NoteReceptors::CheckInput(sf::RenderWindow &Window)
{
const sf::Input& GetInput = Window.GetInput();
if (GetInput.IsKeyDown(sf::Key::Left) && TickL == 0)
{
TickL = 1;
ScaleL = 0.6;
}
else
{
TickL = 0;
}
As said above, it does not work, the code runs as if TickL didn't exist, therefore the scale always stays at 0.5 as long as the key is pressed.
I hope I explained it well enough, what I want to know is how to set it to 0.5 only when the key is first pressed, and then return to 1 even if the key is held down.
I also have if (ScaleL < 1) {ScaleL += 0.1;}
in the main loop so it does increase when the key is released.