World > Backgrounds#

Unterklasse von Appearances Manager.

API-Referenz#

class miniworlds.appearances.backgrounds_manager.BackgroundsManager(parent)[Quellcode]#

Manages background appearances in a world.

This manager is typically accessed via the backgrounds attribute of a World instance.

Example

world.backgrounds.set_background(„assets/backgrounds/forest.png“) bg = world.backgrounds.background world.backgrounds.switch_background(2)

Public Data Attributes:

background

Returns the currently active background.

world

Shortcut for accessing the owning world.

backgrounds

Returns the list of all loaded backgrounds.

Inherited from AppearancesManager

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)

Initializes the BackgroundsManager.

get_background_at_index(index)

Returns the background at a specific index.

add_background(source)

Adds a new background from a given source path.

set_background(source)

Sets the background to the one specified by the source.

create_appearance()

Creates a new background appearance instance.

switch_appearance(source)

Switches to a different background by index or reference.

switch_background(source)

Switches to a different background by index or reference.

Inherited from AppearancesManager

__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 AppearancesManager

_abc_impl

Inherited from ABC

_abc_impl

Private Methods:

Inherited from AppearancesManager

_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.


__init__(parent)[Quellcode]#

Initializes the BackgroundsManager.

Parameter:

parent – The world instance that owns this manager.

add_background(source)[Quellcode]#

Adds a new background from a given source path.

Rückgabetyp:

Background

Parameter:

source – Path to the background resource.

Rückgabe:

The newly added background instance.

Example

world.backgrounds.add_background(„assets/bg/mountain.png“)

property background: Appearance#

Returns the currently active background.

Example

current = world.backgrounds.background

property backgrounds: list[background_mod.Background]#

Returns the list of all loaded backgrounds.

Example

for bg in world.backgrounds.backgrounds:

print(bg.name)

create_appearance()[Quellcode]#

Creates a new background appearance instance.

Rückgabetyp:

Background

Rückgabe:

A new Background object linked to the world.

Example

bg = world.backgrounds.create_appearance()

get_background_at_index(index)[Quellcode]#

Returns the background at a specific index.

Rückgabetyp:

Background

Parameter:

index – Index of the background in the manager.

Rückgabe:

The background at the given index.

Example

bg = world.backgrounds.get_background_at_index(0)

set_background(source)[Quellcode]#

Sets the background to the one specified by the source.

Rückgabetyp:

Background

Parameter:

source – Path to the new background.

Rückgabe:

The background that has been set.

Example

world.backgrounds.set_background(„assets/bg/sea.png“)

switch_appearance(source)[Quellcode]#

Switches to a different background by index or reference.

Marks all actors in the world as dirty for redrawing.

Rückgabetyp:

Appearance

Parameter:

source – Index of background or background instance.

Rückgabe:

The newly activated background.

Example

world.backgrounds.switch_appearance(1) world.backgrounds.switch_appearance(other_bg)

switch_background(source)#

Switches to a different background by index or reference.

Marks all actors in the world as dirty for redrawing.

Rückgabetyp:

Appearance

Parameter:

source – Index of background or background instance.

Rückgabe:

The newly activated background.

Example

world.backgrounds.switch_appearance(1) world.backgrounds.switch_appearance(other_bg)

property world: World#

Shortcut for accessing the owning world.

Example

world = world.backgrounds.world