Async State

class game_state.AsyncState

The State class which works as an individual screen.

Attributes:
state_name: str

The name of the state. Has to be unique among other states.

Added in version 2.4.

manager: AsyncStateManager

The manager to which the state is binded to.

Added in version 2.4.

classmethod __init_subclass__(*, state_name=None, eager_load=False, lazy_load=False)

Arguments you can pass while subclassing the State.

Parameters:
  • state_name (Optional[str]) –

    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): ...
    

Return type:

None

Warning

You cannot set eager_load and lazy_load both to True. 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.

Parameters:

reload (bool) –

A bool indicating whether the state is being loaded for the first time (False) or reloaded (True).

Return type:

None

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.

Parameters:

reload (bool) –

A bool indicating whether the state is being unloaded for the first time (False) or reloaded (True).

Return type:

None

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.

Parameters:

previous_state (Optional[State]) –

The state that was running previously. If there are no previous states, None is passed

Return type:

None

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.

Parameters:

next_state (State) –

The next state that is going to be applied.

Return type:

None