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 The main game window.
Added in version 1.0.
- 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 MainMenu(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.Added in version 2.0.
Warning
This method need not be called manually.
- Return type:
- on_enter(prevous_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 a pygame event needs to be processed.
Added in version 2.0.
Note
This method needs to be called manually.
- Parameters:
event (
Event) –The pygame event object.- Return type: