You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
EGE::SystemEventHandler
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);
}