SFML community forums

Help => General => Topic started by: bonsairobo on January 22, 2013, 11:52:14 pm

Title: If I allow an SFML program to exit by pressing ESC it will also close with mouse
Post by: bonsairobo on January 22, 2013, 11:52:14 pm
This might be something funky with my own computer, but I sent one of my programs to a friend and he had the same problem.

Whenever I poll for an event as written in the code below, my program will close if I circle my mouse cursor around the top or bottom left corners of the window.

The problem is illustrated in this video: http://youtu.be/PD7-y1_H6qo?t=15s

You can try it yourself by downloading my pong game here: http://www.mediafire.com/?6xrvvtbr7qc03jo, but the same problem occurs in any program I make using the method below.

while(tetris.isOpen())
        {
                sf::Event event;
                while(tetris.pollEvent(event))
                {
                        if (event.key.code == sf::Keyboard::Escape)
                                tetris.close();
                }
        }
 
Title: Re: If I allow an SFML program to exit by pressing ESC it will also close with mouse
Post by: eXpl0it3r on January 22, 2013, 11:57:17 pm
Well you then probably need to read the tutorial (http://www.sfml-dev.org/tutorials/2.0/window-events.php) again or probably at all...

If you don't check which event happened, but only check for the key code, then the behavior is undefined, since the key code can hold anything...
Title: Re: If I allow an SFML program to exit by pressing ESC it will also close with mouse
Post by: bonsairobo on January 22, 2013, 11:59:03 pm
my bad