Appearance-Manager#

AppearancesManager ist die Basisklasse von BackgroundsManager und CostumesManager.

Diese Klassen verwalten alle Appearances eines Actors oder einer Welt.

API-Referenz#

class miniworlds.appearances.appearances_manager.AppearancesManager(parent)[Quellcode]#

Abstract base class for managing a collection of costume or background appearances.

Subclasses CostumesManager (for actors) and BackgroundsManager (for worlds) extend this class with their own factory methods and convenience helpers.

Typical use via the public API:

# Switching between costumes
actor.switch_costume(1)
actor.next_costume()

# Switching between backgrounds
world.switch_background(1)
world.next_background()

Public Data Attributes:

image

Image surface of the currently active appearance.

orientation

Returns the orientation values of all managed appearances.

animation_speed

Returns the animation speed of the active appearance.

border

Returns the shared border width for managed appearances.

Public Methods:

__init__(parent)

add_new_appearance(source)

Adds a new Appearance (costume or background) to manager.

set_new_appearance(source)

Replaces the current appearance with a new one.

add_new_appearances(sources)

add_new_appearance_from_list(sources)

create_appearance()

Returns a new appearance (Background instance or Costume instance)

next_appearance()

Switches to next appearance

length()

Returns the number of appearances currently managed.

__len__()

get_appearance_at_index(index)

find_appearance(appearance)

Searches for appearance; returns index of appearance

set_border(value)

Sets the border width for all managed appearances.

set_animated(value)

Enables or disables animation for all managed appearances.

set_animation_speed(value)

Sets the animation speed for all managed appearances.

set_upscaled(value)

Sets whether small images may be scaled up.

set_scaled_to_width(value)

Sets whether appearances should scale to the parent width.

set_scaled_to_height(value)

Sets whether appearances should scale to the parent height.

set_scaled(value)

Sets whether appearances should scale to the parent size.

list()

Returns all appearances in manager as list.

__str__()

Return str(self).

remove_appearance([source])

Removes an appearance (costume or background) from manager

reset()

Removes all managed appearances and resets the manager state.

switch_appearance(source)

Switches the active costume or background.

animate(speed)

Starts animating the currently active appearance.

animate_appearance(appearance, speed)

Switches to a specific appearance and starts animating it.

self_remove()

Implemented in subclasses

__iter__()

__next__()

get_actual_appearance()

Returns the currently active appearance.

Private Data Attributes:

_abc_impl

Inherited from ABC

_abc_impl

Private Methods:

_init_display()

_create_appearance_from_source(source)

_add_default_appearance()

_add_first_appearance(appearance)

_add_appearance_to_manager(appearance)

_set_appearance_defaults()

_set_all(attribute, value)

Sets attribute for all appearance in manager.

_remove_appearance_from_manager(appearance)

Removes an appearance from the manager.


add_new_appearance(source)[Quellcode]#

Adds a new Appearance (costume or background) to manager.

called by add_costume and add_background in subclasses.

Rückgabetyp:

Appearance

add_new_appearance_from_list(sources)[Quellcode]#
Rückgabetyp:

Appearance

add_new_appearances(sources)[Quellcode]#
Rückgabetyp:

None

animate(speed)[Quellcode]#

Starts animating the currently active appearance.

Parameter:

speed – Number of frames between image changes.

animate_appearance(appearance, speed)[Quellcode]#

Switches to a specific appearance and starts animating it.

Parameter:
  • appearance – The appearance to animate.

  • speed – Number of frames between image changes.

property animation_speed#

Returns the animation speed of the active appearance.

property border#

Returns the shared border width for managed appearances.

abstract create_appearance()[Quellcode]#

Returns a new appearance (Background instance or Costume instance)

Rückgabetyp:

Appearance

find_appearance(appearance)[Quellcode]#

Searches for appearance; returns index of appearance

Rückgabetyp:

int

Rückgabe:

Index of found appearance; -1 if appearance was not found.

Rückgabetyp:

int

get_actual_appearance()[Quellcode]#

Returns the currently active appearance.

If no appearance exists yet, a default one is created first.

Rückgabetyp:

Appearance

get_appearance_at_index(index)[Quellcode]#
Rückgabetyp:

Optional[Appearance]

property image: Surface#

Image surface of the currently active appearance.

Rückgabe:

Active appearance image, or a 1x1 fallback surface if no appearance has been created yet.

Rückgabetyp:

pygame.Surface

length()[Quellcode]#

Returns the number of appearances currently managed.

Rückgabetyp:

int

Rückgabe:

Number of costumes or backgrounds in the manager.

Rückgabetyp:

int

list()[Quellcode]#

Returns all appearances in manager as list.

Rückgabetyp:

List[Appearance]

Rückgabe:

All appearances in manager as list

Rückgabetyp:

List[appearance_mod.Appearance]

next_appearance()[Quellcode]#

Switches to next appearance

Rückgabetyp:

Appearance

Rückgabe:

the switched appearance

Rückgabetyp:

appearance_mod.Appearance

property orientation#

Returns the orientation values of all managed appearances.

remove_appearance(source=-1)[Quellcode]#

Removes an appearance (costume or background) from manager

Defaults:

Removes last costume.

Parameter:
  • source – The index of the new appearance or the Appearance which should be removed Defaults to -1

  • costume) ((last)

reset()[Quellcode]#

Removes all managed appearances and resets the manager state.

This is useful when an actor or world should receive a completely new set of costumes or backgrounds.

self_remove()[Quellcode]#

Implemented in subclasses

Rückgabetyp:

None

set_animated(value)[Quellcode]#

Enables or disables animation for all managed appearances.

Parameter:

valueTrue to animate appearances, otherwise False.

set_animation_speed(value)[Quellcode]#

Sets the animation speed for all managed appearances.

Parameter:

value – Number of frames between image changes.

set_border(value)[Quellcode]#

Sets the border width for all managed appearances.

Parameter:

value – Border width in pixels.

set_new_appearance(source)[Quellcode]#

Replaces the current appearance with a new one.

If no appearance exists yet, this behaves like add_new_appearance.

Parameter:

source – Image source, color tuple, surface, costume instance, or None for a default appearance.

Rückgabe:

The newly active appearance.

set_scaled(value)[Quellcode]#

Sets whether appearances should scale to the parent size.

Parameter:

valueTrue to scale managed appearances.

set_scaled_to_height(value)[Quellcode]#

Sets whether appearances should scale to the parent height.

Parameter:

valueTrue to scale to height.

set_scaled_to_width(value)[Quellcode]#

Sets whether appearances should scale to the parent width.

Parameter:

valueTrue to scale to width.

set_upscaled(value)[Quellcode]#

Sets whether small images may be scaled up.

Parameter:

valueTrue to allow upscaling.

switch_appearance(source)[Quellcode]#

Switches the active costume or background.

Rückgabetyp:

Appearance

Parameter:

source – Either the appearance index or the appearance instance.

Rückgabe:

The newly active appearance.