World > Background#

A Background is a child class of Appearance. Most methods and attributes are inherited from the Appearance base class.

API Reference#

class miniworlds.appearances.background.Background(*args, **kwargs)[source]#

Background appearance of a world.

A background can be color-based or image-based, and each world can hold multiple background appearances that can be switched at runtime.

Examples

Add an image background:

world = World() world.add_background(“images/my_image.png”)

Add a color background:

world = World() world.add_background((255, 0, 0, 255))

add_drawing_command(kind, *args, owner=None, **kwargs)[source]#

Add a persistent drawing command to the active background image.

Return type:

dict[str, Any]

add_image(source)[source]#

Add an image source and immediately refresh the window surface.

Return type:

int

animation_length#
clear_drawing_layer(owner=None)[source]#

Clear persistent background drawings.

Return type:

None

Parameters:

owner – If provided, only commands with this owner id are removed.

draw_arc(rect, start, extent, color, width=1, owner=None)[source]#
draw_circle(center, radius, outline=None, fill=None, width=1, owner=None)[source]#
draw_dot(center, size, color, owner=None)[source]#
draw_images#
draw_line(start, end, color, width=1, owner=None)[source]#
draw_polygon(points, outline=None, fill=None, width=1, owner=None)[source]#
draw_polyline(points, color, width=1, owner=None)[source]#
draw_shapes#
draw_text(position, text, color=(0, 0, 0), font=None, align='left', owner=None)[source]#
property drawing_commands: tuple[dict[str, Any], ...]#

Persistent drawing commands rendered onto this background.

font_manager#
get_manager()[source]#

Return the owning BackgroundsManager.

get_rect()[source]#

Return the cached rect of the rendered background image.

property grid: bool | tuple#

Whether a grid overlay is shown.

Accepts True, False, or a color tuple to set the grid color.

id#
image_manager: image_manager.ImageManager#
initialized#
last_image#
loop#
parent: world_mod.World#

Background.parent The world to which the background belongs to

repaint()[source]#

Called 1/frame from world

set_dirty(value='all', status=1)[source]#

Mark the background as dirty and refresh dependent actor visuals.

set_drawing_commands(commands)[source]#

Replace persistent drawing commands and re-render the background.

Return type:

None

show_grid()[source]#

Enable grid rendering for this background.

surface_loaded#
transformations_manager#
property world: World#

Owning world of this background.