jack moore
jack moore

Reputation: 2059

SDL_WaitEvent: How to kill everything in queue?

I'm using this in my main loop:

if (SDL_WaitEvent(&event)) {
            switch (event.type) {
            case SDL_MOUSEBUTTONDOWN:
                mainClicker(event.button.x, event.button.y);
            break;
..... etc

Everything works fine, but:

In "screen 1" user does stuff and clicks a button. The app then does its stuff and shows a result screen with other buttons. The problem is that if you accidentally click before the result screen is fully displayed (2-5 seconds - using SDL_Delay), MOUSEBUTTONDOWN is kinda stored (cached) and then immediately used in screen 2. So if you're "lucky" enough, you can click some of the screen2 buttons even before they're displayed.

Is there a way how to clear SDL event queue (not sure how it's actually called)?

Thanks.

Upvotes: 1

Views: 2429

Answers (1)

Matt Joiner
Matt Joiner

Reputation: 118570

After you process the event to active the result screen, call this before processing the next event:

SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);

After the result screen has loaded, call:

SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_ENABLE);

Upvotes: 1

Related Questions