World > Backgrounds#
Child class of Appearances Manager
- class miniworlds.appearances.backgrounds_manager.BackgroundsManager(parent)[source]#
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:
Returns the currently active background.
Shortcut for accessing the owning world.
Returns the list of all loaded backgrounds.
Inherited from
AppearancesManager
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.
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)add_new_appearances
(sources)add_new_appearance_from_list
(sources)Returns a new appearance (Background instance or Costume instance)
Switches to next appearance
length
()Number of appearance in appearance manager
__len__
()get_appearance_at_index
(index)find_appearance
(appearance)Searches for appearance; returns index of appearance
set_border
(value)set_animated
(value)set_animation_speed
(value)set_upscaled
(value)set_scaled_to_width
(value)set_scaled_to_height
(value)set_scaled
(value)list
()Returns all appearances in manager as list.
__str__
()Return str(self).
remove_appearance
([source])Removes an appearance (costume or background) from manager
reset
()switch_appearance
(source)animate
(speed)animate_appearance
(appearance, speed)Implemented in subclasses
__iter__
()__next__
()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 appearance from manager If self.length == 1, the last costume is removed and a default appearance will be added.
- __init__(parent)[source]#
Initializes the BackgroundsManager.
- Parameters:
parent – The world instance that owns this manager.
- add_background(source)[source]#
Adds a new background from a given source path.
- Return type:
- Parameters:
source – Path to the background resource.
- Returns:
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()[source]#
Creates a new background appearance instance.
- Return type:
- Returns:
A new Background object linked to the world.
Example
bg = world.backgrounds.create_appearance()
- get_background_at_index(index)[source]#
Returns the background at a specific index.
- Return type:
- Parameters:
index – Index of the background in the manager.
- Returns:
The background at the given index.
Example
bg = world.backgrounds.get_background_at_index(0)
- set_background(source)[source]#
Sets the background to the one specified by the source.
- Return type:
- Parameters:
source – Path to the new background.
- Returns:
The background that has been set.
Example
world.backgrounds.set_background(“assets/bg/sea.png”)
- switch_appearance(source)[source]#
Switches to a different background by index or reference.
Marks all actors in the world as dirty for redrawing.
- Return type:
- Parameters:
source – Index of background or background instance.
- Returns:
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.
- Return type:
- Parameters:
source – Index of background or background instance.
- Returns:
The newly activated background.
Example
world.backgrounds.switch_appearance(1) world.backgrounds.switch_appearance(other_bg)