๐ฆ JEEventHandler
Technical reference for the
JEEventHandlerclass of JarEngine.
Inherit from
โข>JEInternBaseClass<โข๐
๐น Overview
JEEventHandler is responsible for managing event watchers and dispatching incoming events to the appropriate callbacks.
Provides:
- Registration and removal of event, keyboard, and mouse watchers.
- Centralized processing of PyGame events.
- Automatic dispatch of matching events to registered callbacks.
JEEventHandler is the core of JarEngineโs event system. It continuously polls PyGame events, wraps them into JEEvent objects, and forwards them to every compatible watcher. It allows games to react to user input without manually iterating through the event queue, providing a clean callback-based architecture.
๐น Location
JarEngine
โ
โโโ events
โ โโโ JEEventHandler
โ
โโโ ...
๐น Data
| Field | Type | Description | Property? | Can be set? |
|---|---|---|---|---|
watchers |
list[JEEventWatcher \| JEKeyWatcher \| JEMouseWatcher] |
List of registered watchers that receive matching events. | True | False |
๐น API
| Function | Arguments | Returns | Description |
|---|---|---|---|
__init__ |
ย | ย | Creates an empty event handler. |
add |
watcher: JEEventWatcher \| JEKeyWatcher \| JEMouseWatcher |
ย | Registers a watcher so it can receive matching events. |
remove |
watcher: JEEventWatcher \| JEKeyWatcher \| JEMouseWatcher |
ย | Removes a previously registered watcher. |
clear |
ย | ย | Removes every registered watcher from the handler. |
has |
code: JEEventCode \| JEKeyCode \| JEMouseCode |
JEBool |
Checks whether at least one watcher is monitoring the specified code. |
process |
game: JEGame, is_single_match: JEBool |
ย | Polls PyGame events, dispatches them to matching watchers, and executes their callbacks. |
๐น Usage
from jarengine import Events
from jarengine import Games
game = Games.JEGame()
def on_quit(game, event):
game.close()
handler = Events.JEEventHandler()
handler.add(
Events.Event.JEEventWatcher(
Events.Event.Event.QUIT,
on_quit
)
)
while game.is_open:
handler.process(game)