开发者

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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜