SFML community forums

Help => Window => Topic started by: GabrielS on May 31, 2013, 09:02:40 pm

Title: [SOLVED] MouseClic / MousePressed
Post by: GabrielS on May 31, 2013, 09:02:40 pm
Hello guys !
I have a little question about mouse event : I do not want to be in the polling loop (that's cool because actually, the mouse can be handled separatly). However, when I clic on the window, the meter counting the number of clics don't increase by 1 but increase depending on how long I let the mouse button pressed.
Question : is it possible to get only once in the loop ( thus triggering the event on the clic and not on the pressed action ) ?
Here is the code :

if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
        sf::Vector2i localPosition = sf::Mouse::getPosition(window);
        if ((myElectrode->getShape()).isPositionInside((sf::Vector2f) localPosition)) // the function always return true at the moment
        {
                count++;
                string windowTitle = to_string((long double) count);
                window.setTitle(windowTitle);
        }
}
 

Thanks in advance,

Gabriel.
Title: Re: MouseClic / MousePressed
Post by: Laurent on May 31, 2013, 10:46:36 pm
Use events instead of real-time states.
Title: Re: MouseClic / MousePressed
Post by: GabrielS on May 31, 2013, 11:19:33 pm
Hello and thanks.. Just, if I understood well,
do you mean i have to do it this way :

Code: [Select]
sf::Event event;
 while (window.pollEvent(event))
 {
     if (event.type == sf::Event::Closed)
         window.close();
     // else if -> event on mouse
 }
Title: Re: MouseClic / MousePressed
Post by: Laurent on June 01, 2013, 09:10:32 am
Yes.