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

Author Topic: Multiple Mouse clicks  (Read 1865 times)

0 Members and 1 Guest are viewing this topic.

togtja

  • Newbie
  • *
  • Posts: 2
    • View Profile
Multiple Mouse clicks
« on: February 09, 2019, 08:39:22 am »
So i have a bool that checks if you have "picked up", then onMouse should be true, if you click again (aka drop it), then it will be false. However, when I click it turns true, then back to false again
sf::RenderWindow window(sf::VideoMode(10,10), "Some Game");
window.setKeyRepeatEnabled(false);
bool onMouse = false;
while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
                if (event.type == sf::Event::Closed)
                        window.close();
                if (event.type == event.MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left && !onMouse) {
                        std::cout << "on Mouse True/Picked up\n";
                        onMouse = true;
                }

                if (event.type == event.MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left && onMouse) {
                        std::cout << "on Mouse False/Dropped\n";
                        onMouse = false;
                }
        }
}
 
I have looked for other similar post, but non have helped my case

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Multiple Mouse clicks
« Reply #1 on: February 09, 2019, 09:06:10 am »
Quote
                if (event.type == event.MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left && !onMouse) {
                        std::cout << "on Mouse True/Picked up\n";
                        onMouse = true;
                }

                if (event.type == event.MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left && onMouse) {
                        std::cout << "on Mouse False/Dropped\n";
                        onMouse = false;
                }
Of course, once you set onMouse to true, you enter the 2nd if. Put your second if inside the else of the first one.

togtja

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Multiple Mouse clicks
« Reply #2 on: February 09, 2019, 09:17:12 am »

 
Of course, once you set onMouse to true, you enter the 2nd if. Put your second if inside the else of the first one.
I feel pretty stupid now. Anyways Thanks a lot for the help

 

anything