title: SFML Mouse click detection
body: <p>I'm coding a game with SFML library.
  I have some buttons and when I click on, I want to do something.</p>
  
  <p>But I have a probleme, I don't know how to detect a simple click, not key released or key pressed, just a click.</p>
  
  <p>I write this code :</p>
  
  <p>Game loop :</p>
  
  <pre><code>void                            GameEngine::gameLoop()
  {
    Menu                                  menu(_win);
  
    while (_win.isOpen() &amp;&amp; gl_quit == false)
      {
        sf::Event         event;
        while (_win.pollEvent(event))
          {
            if (event.type == sf::Event::Closed)
              _win.close();
          }
        menu.mouseEvent(event);
        menu.keyboardEvent();
  
        menu.calcul();
        menu.reDraw();
  
        _win.display();
        _win.clear();
      }
  }
  </code></pre>
  
  <p>Menu.cpp</p>
  
  <pre><code>bool                            Menu::mouseEvent(sf::Event &amp;event)
  {
    if (event.type == sf::Event::MouseButtonReleased)
      {
        if (event.mouseButton.button == sf::Mouse::Left)
          {
            for (std::map&lt;std::string, Button *&gt;::iterator it = _buttons.begin();
                 it != _buttons.end(); ++it)
              {
                if (it-&gt;second-&gt;collide(sf::Mouse::getPosition(_win)))
                  (this-&gt;*(it-&gt;second-&gt;getAction()))();
              }
          }
      }
  }
  </code></pre>
  
  <p>And for example when I click on the "Play" button, this method is called :</p>
  
  <pre><code>void                            Menu::on_Jouer_clicked()
  {
    std::cout &lt;&lt; "fct jouer" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>And the this is the result in consol :</p>
  
  <pre><code>~/Projet/gametest :./game 
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  fct jouer
  </code></pre>
  
  <p>The function is called too many times.</p>