Appearance Manager#

AppearancesManager is the parent class of BackgroundsManager and CostumesManager.

These classes manage all appearances of an actor or world.

API Reference#

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

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.

Examples

actor.switch_costume(1)
actor.next_costume()

world.switch_background(1)
world.next_background()
add_new_appearance(source)[source]#

Add a new appearance to the manager.

This is called by add_costume() and add_background() in subclasses.

Return type:

Appearance

Parameters:

source – Image path, surface, color tuple, costume, or None.

Returns:

The newly active appearance.

add_new_appearance_from_list(sources)[source]#
Return type:

Appearance

add_new_appearances(sources)[source]#
Return type:

None

animate(speed)[source]#

Starts animating the currently active appearance.

Parameters:

speed – Number of frames between image changes.

animate_appearance(appearance, speed)[source]#

Switches to a specific appearance and starts animating it.

Parameters:
  • 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()[source]#

Returns a new appearance (Background instance or Costume instance)

Return type:

Appearance

find_appearance(appearance)[source]#

Searches for appearance; returns index of appearance

Return type:

int

Returns:

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

Return type:

int

get_actual_appearance()[source]#

Returns the currently active appearance.

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

Return type:

Appearance

get_appearance_at_index(index)[source]#
Return type:

Optional[Appearance]

length()[source]#

Returns the number of appearances currently managed.

Return type:

int

Returns:

Number of costumes or backgrounds in the manager.

Return type:

int

list()[source]#

Returns all appearances in manager as list.

Return type:

List[Appearance]

Returns:

All appearances in manager as list

Return type:

List[appearance_mod.Appearance]

next_appearance()[source]#

Switches to next appearance

Return type:

Appearance

Returns:

the switched appearance

Return type:

appearance_mod.Appearance

property orientation#

Returns the orientation values of all managed appearances.

remove_appearance(source=-1)[source]#

Removes an appearance (costume or background) from manager

Defaults:

Removes last costume.

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

  • costume) ((last)

reset()[source]#

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()[source]#

Implemented in subclasses

Return type:

None

set_animated(value)[source]#

Enables or disables animation for all managed appearances.

Parameters:

valueTrue to animate appearances, otherwise False.

set_animation_speed(value)[source]#

Sets the animation speed for all managed appearances.

Parameters:

value – Number of frames between image changes.

set_border(value)[source]#

Sets the border width for all managed appearances.

Parameters:

value – Border width in pixels.

set_new_appearance(source)[source]#

Replaces the current appearance with a new one.

If no appearance exists yet, this behaves like add_new_appearance().

Parameters:

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

Returns:

The newly active appearance.

set_scaled(value)[source]#

Sets whether appearances should scale to the parent size.

Parameters:

valueTrue to scale managed appearances.

set_scaled_to_height(value)[source]#

Sets whether appearances should scale to the parent height.

Parameters:

valueTrue to scale to height.

set_scaled_to_width(value)[source]#

Sets whether appearances should scale to the parent width.

Parameters:

valueTrue to scale to width.

set_upscaled(value)[source]#

Sets whether small images may be scaled up.

Parameters:

valueTrue to allow upscaling.

switch_appearance(source)[source]#

Switches the active costume or background.

Return type:

Appearance

Parameters:

source – Either the appearance index or the appearance instance.

Returns:

The newly active appearance.