SFML community forums

Help => General => Topic started by: Asurael on February 21, 2016, 02:39:43 pm

Title: MouseButtonReleased Event is spamming when moving the mouse
Post by: Asurael on February 21, 2016, 02:39:43 pm
Hello guys,

my problem is that the mousebuttonreleased event does not work for me. Here is the code for my event loop
void Framework::events()
{
        while (mWindow->pollEvent(*mEvent))
        {
        switch (mEvent->type)
        {
            case sf::Event::MouseButtonReleased:
            {
                std::cout << "Test";

            } break;

            default:
                break;
        }
        }
}

When i start my program test gets spammed when i move the mouse but the funny thing is that when i release my left or right mouse button nothing happens. What am I doing wrong?

The events function is in my game loop here is the code for it
void Framework::run()
{
        while (mWindow->isOpen())
        {
        events();
        update();
                render();
        }
}
 

Title: Re: MouseButtonReleased Event is spamming when moving the mouse
Post by: DarkRoku12 on February 22, 2016, 03:29:14 am
Hello guys,

my problem is that the mousebuttonreleased event does not work for me. Here is the code for my event loop
void Framework::events()
{
        while (mWindow->pollEvent(*mEvent))
        {
        switch (mEvent->type)
        {
            case sf::Event::MouseButtonReleased:
            {
                std::cout << "Test";
                break ; // SHOULD BE HERE!!
            }// break; // NOT HERE!!!

            default:
                break;
        }
        }
}



For switch you don't necessary need to use brackets {} :

void Framework::events()
{
        while (mWindow->pollEvent(*mEvent))
        {
        switch (mEvent->type)
        {
            case sf::Event::MouseButtonReleased: // This is OK. :)
                    std::cout << "Test";
                    break ;

            default:
                break;
        }
        }
}
Title: Re: MouseButtonReleased Event is spamming when moving the mouse
Post by: Laurent on February 22, 2016, 09:22:15 am
Quote
                break ; // SHOULD BE HERE!!
            }// break; // NOT HERE!!!
Makes absolutely no difference.
Title: Re: MouseButtonReleased Event is spamming when moving the mouse
Post by: Asurael on February 22, 2016, 04:03:05 pm
Does no one knows whats the problem with my code? :(
Title: Re: MouseButtonReleased Event is spamming when moving the mouse
Post by: eXpl0it3r on February 23, 2016, 12:10:25 am
Create a minimal and complete example, e.g. just the standard game loop + event loop.

If the issue persists then my guess would be that you use outdated SFML header files, i.e. you updated the library files but didn't update the header files (or the other way around).
Title: Re: MouseButtonReleased Event is spamming when moving the mouse
Post by: Asurael on February 23, 2016, 02:41:58 pm
Quote
If the issue persists then my guess would be that you use outdated SFML header files, i.e. you updated the library files but didn't update the header files (or the other way around).

That was the problem! Thank you very much!!
Title: Re: MouseButtonReleased Event is spamming when moving the mouse
Post by: Jabberwocky on February 23, 2016, 04:58:55 pm
Pretty slick guru debugging, eXpl0it3r.