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)

__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