Polling events
Generally speaking, events
are objects that are triggered when something happens; mostly related to the user input. Events are a construct in the underlying operating system. On top of them, SFML provides a nice abstraction layer that is easier to use and cross-platform. SFML goes with a polling design to have you work with events. When an input occurs, the operating system reports it to the application. SFML processes this input, converts it into the corresponding SFML event type, and puts it into a queue of waiting events. In your actual application code, you extract events from this queue using the sf::Window::pollEvent()
function (note that sf::Window
is the base class of sf::RenderWindow
, without the rendering functionality). The pollEvent()
function signature is a bit interesting:
bool sf::Window::pollEvent(sf::Event& event);
Now this is a bit special and might not be self-explanatory. The problem with pollEvent()
is that we want to receive two different values. We...