World > Backgrounds#
Child class of Appearances Manager.
API Reference#
- 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)
- __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)