Jump to content
  • Advertisement
Sign in to follow this  
Kenny77

[SDL] Inconsistent Mouse Input

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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

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!