Sign in to follow this  

Help with SDL events, movement

This topic is 4837 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

I am jumping back into SDL. I can't remember how to allow me to hold down the key and continously update the variable for movement? I have to hit the key 10 times if I want to move 10 units... How can I allow the user to hold the key and the event poll keep taking input? Thanks

Share this post


Link to post
Share on other sites
I like the flag setting idea better personally, though graveyard filla's suggestion is also good. Note that if you don't call SDL_WaitEvent() or SDL_PollEvent(), then you will need to do something like this:


SDL_PumpEvents(); // Updates the event queue
key_status = SDL_GetKeyState(NULL); // Get information about the status of the keyboard

if ( !key_status[SDLK_UP] ) { // The UP key has been released, so exit the loop
break;
}


If you don't call SDL_PumpEvents() before you call SDL_GetKeyState(), then you won't be getting the latest status of the keyboard. (SDL_WaitEvent and SDL_PollEvent both internally call SDL_PumpEvents, so if you have either one of those you shouldn't need to do this).

Share this post


Link to post
Share on other sites
This is what I am doing...

while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_MOUSEMOTION:
break;
case SDL_MOUSEBUTTONDOWN:
break;
case SDL_KEYDOWN:
switch( event.key.keysym.sym )
{
case SDLK_n:
shift_model_x +=1.0f;
break;


Share this post


Link to post
Share on other sites
Hey, all. After you get the pointer to the keyboard with SDL_GetKeyState, you never have to call it again. You just call SDL_PumpEvents once per frame.

I found that out while browsing the doc files.

Share this post


Link to post
Share on other sites

This topic is 4837 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this