π¦ Events
Overview of the
Eventsmodule in JarEngine.
πΉ Overview
Events provides the classes and utilities related to event handling and input monitoring.
It includes:
- Event watchers and dispatcher
- Keyboard and mouse input codes
- Runtime event management
πΉ Contents
| Class | Description |
|---|---|
β’>JEEvent<β’π |
Runtime event object |
β’>JEEventHandler<β’π |
Event dispatcher |
β’>JEEventCode<β’π |
Single event code |
β’>JEEventCodeGroup<β’π |
Event code group |
β’>JEEventWatcher<β’π |
Event callback watcher |
β’>JEKeyCode<β’π |
Single keyboard code |
β’>JEKeyCodeGroup<β’π |
Keyboard code group |
β’>JEKeyWatcher<β’π |
Keyboard input watcher |
β’>JEMouseCode<β’π |
Single mouse code |
β’>JEMouseCodeGroup<β’π |
Mouse code group |
β’>JEMouseWatcher<β’π |
Mouse input watcher |
πΉ Usage
from jarengine import JEGame, JEEvtQuit, JEKey_Space, JETrue
from jarengine.events import Event, EventKeyboard
game = JEGame(use_input=JETrue)
# Create event callbacks
def on_quit(game, event):
game.close()
def on_space(game, event):
print("Space pressed")
# Register event watchers
game.event.add(
Event.JEEventWatcher(
JEEvtQuit,
on_quit
)
)
game.event.add(
EventKeyboard.JEKeyWatcher(
JEKey_Space,
on_space
)
)
while game.is_open:
game.update()
Events are registered as watchers and automatically processed by the gameβs event manager.
πΉ Notes
Useful information:
- Event, keyboard and mouse codes can be combined into groups.
- Runtime events are automatically generated from PyGame events.
- Avoid creating custom runtime events manually.