class documentation

class Stage:

Constructor: Stage()

View In Hierarchy

A Stage is the main element that contains all the Sprites and dispatches events to the Sprites. It also contains a backdrop image.

Method __init__ Constructor
Method add Undocumented
Method add_backdrop Add a background image to the stage. If this is the first one added, it will be automatically switched to. @param image Either a filename or an already converted Surface @param name (optional) A name to use for this backdrop...
Method add_backdrops Adds several backdrops at once. @param backdrops Positional arguments adding an arbitrary number of backdrops in order, of things compatible with add_backdrop() @param kwBackdrops Keyword arguments adding backdrops with the name as the key, and a value compatible with add_backdrop().
Method broadcast Undocumented
Method destroy Undocumented
Method forever Undocumented
Method next_backdrop Undocumented
Method on_init If you inherit from Stage to group your scenes and sprites, override this to create and add your sprites. This is slightly easier than having to make your own __init__() and needing to call super().__init__(), although that is still valid...
Method previous_backdrop Undocumented
Method random_backdrop Undocumented
Method remove Undocumented
Method run Run the async function in the background until completion or until this stage is destroyed. TODO: cancel tasks on stage destroy
Method sprites Undocumented
Async Method switch_backdrop_and_wait Undocumented
Method switch_backdrop_to Undocumented
Method when_clicked When a any part of the stage is clicked, call the given handler If allClicks=True, this will be called even if there are sprites at this point too.
Method when_drawing Register an event handler to be called when the screen and all sprites are done drawing. This gives a chance to manually draw more stuff with raw pygame commands on the raw pygame Surface. The callback should look like this: def drawExtraStuff(stage, surface): pygame...
Method when_key_pressed Undocumented
Method when_started Undocumented
Property backdrop_name Undocumented
Property backdrop_number Note: starts at 0. May be -1 if there are no backdrops at all.
Async Method _ask_prompt Draws the text box on the string and asynchronously waits until the user has entered the value. @return answer as a string
Method _on_key_down Undocumented
Method _on_mouse_down Undocumented
Method _on_mouse_motion Undocumented
Method _on_mouse_up A click happens on mouse up
Method _sprite_move_layers Used by sprite layer methods to reorder the sprite in the stage's drawing order list.
Method _start Undocumented
Method _update Draw everything. TODO: draw only what changed.
Instance Variable _allClickEvents Undocumented
Instance Variable _backdropId Undocumented
Instance Variable _backdrops Undocumented
Instance Variable _backgroundTasks Undocumented
Instance Variable _dialog Undocumented
Instance Variable _draw_raw Undocumented
Instance Variable _keyHandlers Undocumented
Instance Variable _name_lookup Undocumented
Instance Variable _on_click Undocumented
Instance Variable _on_start Undocumented
Instance Variable _on_tick Undocumented
Instance Variable _sprites Undocumented
def __init__(self):

Constructor

def add(self, *sprites):

Undocumented

def add_backdrop(self, image: Union[str, pygame.Surface], name: str = None):

Add a background image to the stage. If this is the first one added, it will be automatically switched to. @param image Either a filename or an already converted Surface @param name (optional) A name to use for this backdrop. If omitted, then a name is generated from its 0-based index.

def add_backdrops(self, *backdrops, **kwBackdrops):

Adds several backdrops at once. @param backdrops Positional arguments adding an arbitrary number of backdrops in order, of things compatible with add_backdrop() @param kwBackdrops Keyword arguments adding backdrops with the name as the key, and a value compatible with add_backdrop().

def broadcast(self, messageName, argDictionary={}, excludeOriginator=None):

Undocumented

def destroy(self):

Undocumented

def forever(self, functionToCall):

Undocumented

def next_backdrop(self):

Undocumented

def on_init(self):

If you inherit from Stage to group your scenes and sprites, override this to create and add your sprites. This is slightly easier than having to make your own __init__() and needing to call super().__init__(), although that is still valid. TODO: init vs start is confusing. Make it work for both 'when_started' and subclassing, and for both sync and async...

def previous_backdrop(self):

Undocumented

def random_backdrop(self):

Undocumented

def remove(self, sprite):

Undocumented

def run(self, coroutine):

Run the async function in the background until completion or until this stage is destroyed. TODO: cancel tasks on stage destroy

def sprites(self):

Undocumented

async def switch_backdrop_and_wait(self):

Undocumented

def switch_backdrop_to(self, nameOrIndex: Union[str, int]):

Undocumented

def when_clicked(self, handler, allClicks=False):

When a any part of the stage is clicked, call the given handler If allClicks=True, this will be called even if there are sprites at this point too.

def when_drawing(self, callback):

Register an event handler to be called when the screen and all sprites are done drawing. This gives a chance to manually draw more stuff with raw pygame commands on the raw pygame Surface. The callback should look like this: def drawExtraStuff(stage, surface): pygame.draw.rect(...) # e.g.

def when_key_pressed(self, key, functionToCall):

Undocumented

def when_started(self, functionToCall):

Undocumented

@property
backdrop_name: str =

Undocumented

@property
backdrop_number: int =

Note: starts at 0. May be -1 if there are no backdrops at all.

async def _ask_prompt(self):

Draws the text box on the string and asynchronously waits until the user has entered the value. @return answer as a string

def _on_key_down(self, event):

Undocumented

def _on_mouse_down(self, event):

Undocumented

def _on_mouse_motion(self, event):

Undocumented

def _on_mouse_up(self, event):

A click happens on mouse up

def _sprite_move_layers(self, sprite: Sprite, howmany: int):

Used by sprite layer methods to reorder the sprite in the stage's drawing order list.

def _start(self):

Undocumented

def _update(self, screen):

Draw everything. TODO: draw only what changed.

_allClickEvents =

Undocumented

_backdropId =

Undocumented

_backdrops: list =

Undocumented

_backgroundTasks =

Undocumented

_dialog =

Undocumented

_draw_raw =

Undocumented

_keyHandlers: dict =

Undocumented

_name_lookup: dict =

Undocumented

_on_click =

Undocumented

_on_start =

Undocumented

_on_tick =

Undocumented

_sprites: list =

Undocumented