[SDL] Inconsistent Mouse Input

Started by
4 comments, last by rip-off 15 years, 9 months ago
I'm trying to get the mouse input so I can advance from the intro screen, but it's pretty inconsistent (usually takes a few clicks to get it to continue). I poll for the escape key earlier in the game loop so it can exit, and that works no problem.

if (currentScreen == listSize)
{
    if (SDL_PollEvent(&mouseEvent))
    {
        if (mouseEvent.type == SDL_MOUSEBUTTONDOWN)
        {
            if (mouseEvent.button.button == SDL_BUTTON_LEFT)
            {
                Cleanup();
                ChangeState(game, MenuState::Instance());
            }
        }
    }
}

The only other things that are happening during this is the screen is drawing, and updating the currentTime variable.
Advertisement
Where else do you poll for events? Typically, you should only have a single, centralised location for this. For example, I see no test for the ESC key in your code.

If you have more than one poll loop and you are not careful, you can easily "drop" or "lose" events that should be handled.
I have the check for the escape key above the call to the HandleEvents function (of the current state). The game engine calls the HandleEvents function, which calls the HandleEvents function of the state on the top of the stack. Is there a way I could manage input with my architecture like this?
Is your setup like the one described in this post? If so - can you use the code example I posted as a basis for your solution. If not, can you detail how it differs?
That's actually the article (Game States) I was reading. So in this case should I just poll events at the main loop and pass them to the HandleEvents() of the current state?
Well, does it fix the problem? It seems a relatively simple way of handling events, and if implemented correctly it should not drop any events.

This topic is closed to new replies.

Advertisement