Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] MouseClic / MousePressed  (Read 2095 times)

0 Members and 1 Guest are viewing this topic.

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
[SOLVED] MouseClic / MousePressed
« 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.
« Last Edit: June 04, 2013, 05:14:24 pm by GabrielS »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: MouseClic / MousePressed
« Reply #1 on: May 31, 2013, 10:46:36 pm »
Use events instead of real-time states.
Laurent Gomila - SFML developer

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: MouseClic / MousePressed
« Reply #2 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
 }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: MouseClic / MousePressed
« Reply #3 on: June 01, 2013, 09:10:32 am »
Yes.
Laurent Gomila - SFML developer

 

anything