Async State¶
- class game_state.AsyncState¶
The State class which works as an individual screen.
- Variables:
state_name (str) –
The name of the state. Has to be unique among other states.
Added in version 2.4.
manager (StateManager) –
The manager to which the state is bound to.
Added in version 2.4.
state_args (Optional[types.MappingProxyType]) –
A frozen dict-like snapshot of the arguments passed to the state during initialization.
Added in version 2.5.
state_id (Optional[Union[str, int]]) –
The ID attached to the state when it is used as an overlay state. This attribute remains
Noneif it’s used as a regular state.Added in version 2.5.
- classmethod __init_subclass__(*, state_name=None, eager_load=False, lazy_load=False)
- Overloads:
cls, state_name (Optional[str]), eager_load (Literal[False]), lazy_load (Literal[False]) → None
cls, state_name (Optional[str]), eager_load (Literal[True]), lazy_load (Literal[False]) → None
cls, state_name (Optional[str]), eager_load (Literal[False]), lazy_load (Literal[True]) → None
Arguments you can pass while subclassing the State.
- Parameters:
- The name of the state. If no state_name is passed, it uses the identifier’s name.
Added in version 2.4.
class Game(AsyncState, state_name="GameState"): ...
eager_load (
bool) –Automatically marks this class to be loaded eagerly.Added in version 2.4.
class MainMenu(AsyncState, eager_load=True): ...
lazy_load (
bool) –Automatically marks this class to be loaded lazily.Added in version 2.4.
class PauseMenu(AsyncState, lazy_load=True): ...
Warning
You cannot set
eager_loadandlazy_loadboth toTrue. You can only enable one (or none) of them.
- async on_load(reload)¶
Called when the state is loaded into the
AsyncStateManager.This listener is invoked both during the initial load of the state and when the state is reloaded.
Added in version 2.4.
Note
This method need not be called manually.
- async on_unload(reload)¶
Called when the state is being unloaded from the
AsyncStateManager.This listener is invoked both during the initial load of the state and when the state is reloaded.
Added in version 2.4.
Note
This method need not be called manually.
- async on_enter(previous_state)¶
This listener is called once when a state has been switched and is entering the current state.
Added in version 2.4.
Note
This method need not be called manually.
- async on_leave(next_state)¶
This listener is called once when the state has been switched and is exiting the current one.
Added in version 2.4.
Note
This method need not be called manually.
- async on_overlay_open(temporary)¶
When an overlay state is opened, via
AsyncStateManager.open_overlay(), the respective state gets this method called.Added in version 2.5.
Note
This method need not be called manually.
- async on_overlay_close(temporary)¶
When an overlay state is closed, via
AsyncStateManager.close_overlay()orAsyncStateManager.close_all_overlays(), the respective state(s) gets this method called.Added in version 2.5.
Note
This method need not be called manually.