Trying to figure out how to close a window using a button, in this case the 'Esc'-button. In my first approach I tried going like this:
if (sf::event.type == sf::Keyboard::Escape)
window.close();
That didn't turn out very well, doesn't look like my program notices me pressing the Escape button. So I tried this approuch:
if (sf::event.type == sf::Keyboard::isKeyPressed(sf::Keyboard::Esc))
window.close();
That didn't work either, and just before I was about to ask here I figured out that this line actually works (thou it doesn't feel right since I am actually handling events?)
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Esc))
window.close();
My question is; what is the right way to do it? And why doesn't if work writing like I did first? It seems that' according to YouTube-videos the first and second approach works. But in SFML 2.0 and forward, only the last one does. Is that the case?