State¶
- class game_state.State¶
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 1.1.
- window:
pygame.Surface Deprecated since version 2.3.0:
To add class attributes to your own state system, make a base state (with your custom attributes) and make all your states inherit from it. Check the official guide for more info.Added in version 1.0.
The main game window.
- manager:
StateManager The manager to which the state is binded to.
Added in version 1.0.
- state_name:
- classmethod __init_subclass__(*, state_name=None, eager_load=False, lazy_load=False)
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 1.1.
class Game(State, state_name="GameState"): ...
eager_load (
bool) –Automatically marks this class to be loaded eagerly.Added in version 2.2.
class MainMenu(State, eager_load=True): ...
lazy_load (
bool) –Automatically marks this class to be loaded lazily.Added in version 2.2.
class PauseMenu(State, lazy_load=True): ...
- Return type:
Warning
You cannot set
eager_loadandlazy_loadboth toTrue. You can only enable one (or none) of them.
- on_setup()¶
This listener is only called once while being loaded into the
StateManager. This is also called when reloading the State.Deprecated since version 2.3.0:
Replaced byon_load()as it’s more explicit about it’s function and allows you to handle state reloads separately.Added in version 2.0.
Warning
This method need not be called manually.
- Return type:
- on_load(reload)¶
Called when the state is loaded into the
StateManager.This listener is invoked both during the initial load of the state and when the state is reloaded.
Added in version 2.3.0.
Warning
This method need not be called manually.
- on_unload(reload)¶
Called when the state is being unloaded from the
StateManager.This listener is invoked both during the initial load of the state and when the state is reloaded.
Added in version 2.3.0.
Warning
This method need not be called manually.
- 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.0.
Warning
This method need not be called manually.
- 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.0.
Warning
This method need not be called manually.
- process_event(event)¶
To be called when an event needs to be processed.
Changed in version 2.3:
Changed the type ofeventfrompygame.Eventtotyping.AnyAdded in version 2.0.
Note
This method needs to be called manually.
- process_update(*args)¶
The main game loop method to be executed through the
StateManager.Added in version 2.0.
Note
This method needs to be called manually.