SFML community forums

Help => Graphics => Topic started by: togtja on February 09, 2019, 08:39:22 am

Title: Multiple Mouse clicks
Post by: togtja 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
Title: Re: Multiple Mouse clicks
Post by: G. 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.
Title: Re: Multiple Mouse clicks
Post by: togtja 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