Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - SkullBlade

Pages: [1]
1
Window / Detecting if a key was pressed, not if it is always down
« on: December 09, 2009, 09:17:48 pm »
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:

Code: [Select]

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
Code: [Select]
if (ScaleL < 1) {ScaleL += 0.1;} in the main loop so it does increase when the key is released.

Pages: [1]