SFML community forums

Help => Window => Topic started by: OrientatedCookie on April 23, 2015, 10:13:09 pm

Title: sf::Keyboard question
Post by: OrientatedCookie on April 23, 2015, 10:13:09 pm
I am making an app that need keyboard input, and I need it so when you press a key it 'permantley' makes a sprite appear, not just while the key is pressed. Not sure how to do this. And yes I have read the tutorials and looked for other questions like this, but it says sf::keyboard has only one function which isKeyPressed. Here is the bit of code
if (sf::Keyboard:IsKeyPressed(sf::Keyboard::S))
{
//something
}
//need the sprite to draw here if the key has been pressed once
                                               
Title: Re: sf::Keyboard question
Post by: blojayble on April 23, 2015, 10:17:21 pm
bool pressed = false;
//before loop

if (sf::Keyboard:IsKeyPressed(sf::Keyboard::S))
{
      pressed = true;
}
//need the sprite to draw here if the key has been pressed once
if(pressed) drawSprite();

Something like this?             
Title: Re: sf::Keyboard question
Post by: Jesper Juhl on April 23, 2015, 10:20:17 pm
Simple.
1. Detect key press
2. Remember that key was pressed.
3. Display sprite if key was ever pressed (see 2).

Your program can save state beyond a single frame you know.
Title: Re: sf::Keyboard question
Post by: OrientatedCookie on April 23, 2015, 10:21:31 pm
Thanks for quick response :) I think I got it now