App#
App manages the pygame window and the active worlds. Most beginner projects
do not need to create an App directly because world.run() starts the default
application loop.
Use App only when you intentionally manage more than one world or need direct
control over the application lifecycle.
API Reference#
- class miniworlds.base.app.App(title, world)[Quellcode]#
Main application class for Miniworlds. Created automatically when world.run() is called for the first time.
- Verursacht:
NoRunError – If run() is not called from the main module.
- __init__(title, world)[Quellcode]#
Initializes the App and all its managers.
- Parameter:
title – Title for the window.
world – The initial world object to be run.
- add_display_to_repaint_areas()[Quellcode]#
Adds the full screen area to the repaint queue.
- add_running_world(world)[Quellcode]#
- Rückgabetyp:
- static check_for_run_method()[Quellcode]#
Verifies that .run() is called in the user’s main module. Prints a warning if it’s not found (except in emscripten or notebooks).
- display_repaint()[Quellcode]#
Repaints the regions marked as dirty (called every frame).
- display_update()[Quellcode]#
Repaints the full display if it was marked dirty.
Bemerkung
This could be merged with display_repaint and update_surface.
- classmethod get_path()[Quellcode]#
- classmethod get_platform()[Quellcode]#
- Rückgabetyp:
PlatformAdapter
- classmethod get_running_app()[Quellcode]#
- classmethod get_running_world()[Quellcode]#
- classmethod get_window()[Quellcode]#
- Rückgabetyp:
Optional[Window]
- init_app()[Quellcode]#
Initializes global resources (e.g., image cache).
- prepare_mainloop()[Quellcode]#
Prepares all world objects for drawing.
- quit(exit_code=0)[Quellcode]#
Signals the mainloop to exit.
- Parameter:
exit_code – Exit code to use when quitting.
- register_path(path)[Quellcode]#
Registers the app path for relative resource access.
- Parameter:
path – Path to the project directory.
- remove_running_world(world)[Quellcode]#
- Rückgabetyp:
- static reset(unittest=False, file=None)[Quellcode]#
Resets all app globals.
- Parameter:
unittest – Whether the reset is being called in a unit test context.
file – Optional file path to use for setting the base path.
- resize()[Quellcode]#
Resizes the window surface and updates all layout-related components.
- async run(image, fullscreen=False, fit_desktop=False, replit=False)[Quellcode]#
Starts the app and enters the mainloop.
- Parameter:
image – The background image to display.
fullscreen – Whether to start in fullscreen mode.
fit_desktop – Whether to adapt the window to desktop size.
replit – Whether running in replit environment.
- set_running_world(world)[Quellcode]#
- Rückgabetyp:
- async start_mainloop()[Quellcode]#
Starts the main event loop.