Jump to content
  • Advertisement
Sign in to follow this  
Bytez

SDL_PollEvent troubles

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

ive got into a bit of trouble with SDL_PollEvent, basically i have to update the events of course and i use SDL_PollEvent... now if the program enters a loop say maybe for inputting a name or something then PollEvent isnt being called and the window will freeze up. how does everyone handle this?

Share this post


Link to post
Share on other sites
Advertisement
Personally I have a global variable such as bool quit which I assign to false. Then the main loop is while(!quit). For other loop I throw in another SDL_PollEvent and if they decide to quit I set quit to true so the main loop stops and then I break from the current loop.

However I'm new to this too, so there might be a better way.

Share this post


Link to post
Share on other sites
i did think about that, it works but erm im also sure there must be another way.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bytez
... now if the program enters a loop say maybe for inputting a name or something then PollEvent isnt being called and the window will freeze up.


For inputting a name, you do something like this:


std::string input;

int main()
{

setup();
while( SDL_PollEvent( &event ) )
{
switch(event.type)
{
case SDL_KEYDOWN:
{
if( event.key.keysym.sym == SDLK_RETURN )
{
setPlayersName( input );
}
else
{
input += getCharFromKey( event.key.keysym.sym );
}
}

}
}



The trick is not to go into an explicit loop. You run the "loop" by using PollEvent and then signal when you are done manually. You could have a bool indicating whether you are collection input for a string or normal game input, as a simplistic way of handling it.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!