SFML community forums

Help => General => Topic started by: Deadpool18 on March 18, 2016, 11:54:31 pm

Title: Mouse isButtonReleased
Post by: Deadpool18 on March 18, 2016, 11:54:31 pm
I need to use the mouse to launch certain events and animation in my school project using SFML 2.3. In the sf::Mouse class documnentation you mention the MouseButtonReleased in this exact context :
"Compared to the MouseMoved, MouseButtonPressed and MouseButtonReleased events, sf::Mouse can retrieve the state of the cursor and the buttons at any time (you don't need to store and update a boolean on your side in order to know if a button is pressed or released), and you always get the real state of the mouse, even if it is moved, pressed or released when your window is out of focus and no event is triggered."

BUT there doesn't exist a method isButtonReleased like there is a isButtonPressed...... WHY ? I need that method !
Title: Re: Mouse isButtonReleased
Post by: bitano on March 19, 2016, 12:02:16 am
There is an event sf::Event::MouseButtonReleased :-)
Title: Re: Mouse isButtonReleased
Post by: ka0s420 on March 19, 2016, 12:05:29 am
you'll need to use the event queue for that. Think about it, it doesn't make sense to constantly check if mousebutton is released, released buttons are move like switches they can be on or off.  when you're not using an event queue and you press the mouse button, it registers more than one click, so every time you let go of the mouse button it would register several times. I cant think how that would be useful.

here's how to do it with an event queue:
sf::Event event;

        while (mWindow.pollEvent(event)) {

                switch (event.type)
                {
                case sf::Event::MouseButtonReleased:
                 //do something
         break;
 
Title: Re: Mouse isButtonReleased
Post by: G. on March 19, 2016, 12:09:59 am
If a button isn't pressed, it is released..
Title: Re: Mouse isButtonReleased
Post by: bitano on March 19, 2016, 12:10:40 am
If a button isn't pressed, it is released..
...Or it wasn't pressed at all :P