sdl key state question
In my current demo you have to press the 'p' key to pause the game. The only problem is the game resumes after you release the 'p' key. Is there an easy way to make it so that when I push the 'p' key the game will pause until the 'p' key is pushed again???
Thanks for any tips or tricks on the matter.
oops.......I forgot I am using events....
if(event.key.keysym.sym == SDLK_p)
{
Mix_PauseMusic();
GamePaused =! GamePaused;
}
if(event.key.keysym.sym == SDLK_p)
{
Mix_PauseMusic();
GamePaused =! GamePaused;
}
It's because you get an event when you press the key and one when you release it. Since you don't check what type of event it is (only if it's related to the 'p' key), you toggle the pause when the key is pressed and when it's released. Toggling the pause state only when the event is a SDL_KEYDOWN (and not when it's SDL_KEYUP) should do the trick.
FWIW, I answered your question here already. [grin]
FWIW, I answered your question here already. [grin]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement