Class | SFML::Event |
In: |
window/main.cpp
|
Parent: | Object |
SFML::Event holds all the informations about a system event that just happened.
Events are retrieved using the SFML::Window#GetEvent function.
A SFML::Event instance contains the type of the event (mouse moved, key pressed, window closed, …) as well as the details about this particular event. Please note that the event parameters are defined in a union, which means that only the member matching the type of the event will be properly filled; all other members will have undefined values and must not be read if the type of the event doesn‘t match. For example, if you received a KeyPressed event, then you must read the event.Key
member, all other members such as event.MouseMove or event.Text will have undefined values.
The ruby version differs from C++ in that the parameters are still stored in a union but that the values can be directly accessed from the event object. If you try to access any data which would be considered undefined then SFML::SomeKindOfException will be thrown.
Usage example:
while event = window.getEvent() # Request for closing the window if event.type == SFML::Event::Closed window.close # The escape key was pressed if ( event.type == sf::Event::KeyPressed ) && ( event.code == SFML::Key::Escape ) window.close # The window was resized if event.type == SFML::Event::Resized DoSomethingWithTheNewSize(event.size); # etc ... end
Closed | = | INT2NUM( sf::Event::Closed ) |
Resized | = | INT2NUM( sf::Event::Resized ) |
LostFocus | = | INT2NUM( sf::Event::LostFocus ) |
GainedFocus | = | INT2NUM( sf::Event::GainedFocus ) |
TextEntered | = | INT2NUM( sf::Event::TextEntered ) |
KeyPressed | = | INT2NUM( sf::Event::KeyPressed ) |
KeyReleased | = | INT2NUM( sf::Event::KeyReleased ) |
MouseWheelMoved | = | INT2NUM( sf::Event::MouseWheelMoved ) |
MouseButtonPressed | = | INT2NUM( sf::Event::MouseButtonPressed ) |
MouseButtonReleased | = | INT2NUM( sf::Event::MouseButtonReleased ) |
MouseMoved | = | INT2NUM( sf::Event::MouseMoved ) |
MouseEntered | = | INT2NUM( sf::Event::MouseEntered ) |
MouseLeft | = | INT2NUM( sf::Event::MouseLeft ) |
JoyButtonPressed | = | INT2NUM( sf::Event::JoyButtonPressed ) |
JoyButtonReleased | = | INT2NUM( sf::Event::JoyButtonReleased ) |
JoyMoved | = | INT2NUM( sf::Event::JoyMoved ) |
Count | = | INT2NUM( sf::Event::Count ) |
joyButton | [R] | |
joyMove | [R] | |
key | [R] | |
mouseButton | [R] | |
mouseMove | [R] | |
mouseWheel | [R] | |
size | [R] | |
text | [R] | |
type | [R] |
You should never call this function directly. You should only aquire event‘s trough SFML::Window#getEvent or SFML::Window#waitEvent, if you need to pass data to a method that takes an event instance then make a proxy instance to simulate an event. NOTE: Using this method works but it will act constant as you can‘t access any values.