Quantcast
Channel: How to register a mouse click in SFML 2.5.1 - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to register a mouse click in SFML 2.5.1

$
0
0

So, I have this code inside my game loop, which executes every frame:

   if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) == true) {            switch (j) {...}   }

With the way this code is setup, the switch case inside the condition will end up executing every frame as long as the left mouse button is held down, which is causing me some issues...

What I want instead is for the switch case to execute after a single click, meaning after the mouse button is pressed and then released, and sf::Mouse::isButtonPressed seems perfect for the job, if not for the fact it's no longer a thing anymore in the current version of SFML (2.5.1) for some odd reason. (Which is why any possible duplicates of this question that were made before this function was removed are no longer viable)

So what I tried is this :

        if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) == true) {            if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) == false) {                switch (j) {...}            }        }

Thinking that the program will first check if the button is pressed, and then no longer pressed, and only execute the switch case if both conditions are respectively met, but that didn't work and now the switch case stopped executing entirely.

So, how do I get the program to execute instructions once every single mouse click, after a button is pressed and then released?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images