1
Window / sf::Event::MouseButtonReleased fires twice
« on: April 12, 2022, 07:32:29 pm »
Hello! I noticed that, for whatever reason, sf::Event::MouseButtonReleased was firing twice (once when a mouse button was pressed and once when it was released). Why is this happening? I have shortened my code to this small snippet that causes the issue:
#include <iostream>
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow win(sf::VideoMode(800, 800), "window");
while (win.isOpen()) {
sf::Event e;
while (win.pollEvent(e)) {
switch (e.type) {
case sf::Event::Closed:
win.close();
case sf::Event::MouseButtonPressed:
std::cout << "mouse button pressed\n";
case sf::Event::MouseButtonReleased:
std::cout << "mouse button released\n";
}
}
win.clear();
win.display();
}
}
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow win(sf::VideoMode(800, 800), "window");
while (win.isOpen()) {
sf::Event e;
while (win.pollEvent(e)) {
switch (e.type) {
case sf::Event::Closed:
win.close();
case sf::Event::MouseButtonPressed:
std::cout << "mouse button pressed\n";
case sf::Event::MouseButtonReleased:
std::cout << "mouse button released\n";
}
}
win.clear();
win.display();
}
}