Game Development Reference
In-Depth Information
Using events
After we get the event by calling
Window::pollEvent()
, we can check its type by
looking at
Event::type
. The event is of type
Event::EventType
, which is an enum
inside the
Event
class. Here is how a typical close event can be implemented:
Here, the
Window::close()
function will take care of closing the window. If a
win-
dow
variable gets out of scope, the destructor is called, and the
window
is closed.
If we want to handle more than one event, it makes sense to use the
switch
statement, as
it improves readability. Let's see how the keyboard key presses and releases work: