Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a menu system with four screens and six buttons. I have created a button class and it works great. I even have events for the buttons working. The problem is that I have to run the events inside the game loop. This causes me to wait on a menu screen. Is there a way with SDL and c++ to wait until an even fires aside from setting a variable on button click and waiting in a while loop?

share|improve this question
up vote 2 down vote accepted

SDL allows you to wait for an event with... SDL_WaitEvent. (That's one of the first results if you search for "SDL wait event".) However, it's not exactly clear what your problem is, since running inside a while loop is the standard procedure for games. So it's also not clear that SDL_WaitEvent is the solution to your issue.

When implementing a GUI in a game the usual method is to have the main loop collect the events, and then you send the events to the GUI to be handled. So for example, you might wait for a SDL_MOUSEBUTTONDOWN event, collect the click position from the event, and then pass that to each button in turn to see if the click was on that button - and if so, execute the associated code. You wouldn't generally need to wait at all - the event is read by the main game loop and then handed off to the GUI for potential processing.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.