• Advertisement
Sign in to follow this  

SDL Keystate help

This topic is 2353 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font=arial, verdana, tahoma, sans-serif][size=2]
Uint8 *keystate = SDL_GetKeyState(NULL);

while(quit != true)[/font]
{
{
if(keystate[SDLK_DOWN])
{
paddle_y = paddle_y + 1;
if(paddle_y > 500){paddle_y = 500;}
apply_surface(paddle_y);
}}


for some reason my keystates isnt working, i could make this work using "sdl_pollevent" but i would like it so that as long as user is holding the down key my function runs. I am doing this to make a paddle in my pong game go down, or if there is a better way to handle continuous inut, plz tell me how.
Help would be gratly appreciated
thanks

Share this post


Link to post
Share on other sites
Advertisement
Try doing:
SDL_GetKeyState

Inside of your while loop so it gets the keystate every frame.

Share this post


Link to post
Share on other sites
SDL_GetKeyState returns the same array every time so it doesn't matter if you call it inside or outside the loop.

zacaj is right. Normally when you use SDL_PollEvent or SDL_WaitEvent you don't need to call SDL_PumpEvents because these functions calls SDL_PumpEvents on their own. Here it is needed or otherwise the key state will never update.

Share this post


Link to post
Share on other sites

SDL_GetKeyState returns the same array every time so it doesn't matter if you call it inside or outside the loop.

zacaj is right. Normally when you use SDL_PollEvent or SDL_WaitEvent you don't need to call SDL_PumpEvents because these functions calls SDL_PumpEvents on their own. Here it is needed or otherwise the key state will never update.


Thanks for the reply guys, can you tell me how to use Pump event or give me a link explaining it, because i cant seem to find a decent tutorial on it

Share this post


Link to post
Share on other sites
The SDL documentation wiki has some information: http://www.libsdl.org/cgi/docwiki.cgi/SDL_PumpEvents

Share this post


Link to post
Share on other sites
Thank you guys so much, i finally got my paddle working, what i did was i put SDL_Pumpevents as soon as the loop starts and then inside i have my if statements. Thanks again :D

Share this post


Link to post
Share on other sites
You'll need to consume events from the event queue or the OS may assume your application is unresponsive. At the very least, you'll want to be processing SDL_QUIT events too.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement