-
Notifications
You must be signed in to change notification settings - Fork 1
System Events
sppmacd edited this page Apr 12, 2021
·
1 revision
In this tutorial you will learn one of the ways to handle system events in EGE.
There are some ways to handle keyboard events:
- Inheriting from GUIScreen and override on(Event)() functions - more suitable for custom GUI screens
- Inheriting from (Default)SystemEventHandler and registering it in GameLoop - more suitable for global events (like game keybinds) The first way will be described in (More about User Interface...) chapter.
The basic class for creating event handlers is EGE::SystemEventHandlers. Again, you must to inherit this class:
class MyEventHandler : public EGE::SystemEventHandler
{
public:
virtual void onMouseButtonPress(sf::Event::MouseButtonEvent& event) override
{
//...
}
};
Now you can place some code to event handler:
if(event.button == sf::Mouse::Left)
{
// Add new object.
auto scene = MyGameLoop::instance().scene;
scene->addNewObject<MyObject>(scene);
}
Full source codes can be downloaded in examples repo.