Appearance#
Appearance is the parent class of Background and Costume.
Backgrounds and costumes are appearances as well, so they inherit all attributes and methods defined in this class.
API Reference#
- class miniworlds.appearances.appearance.Appearance(*args, **kwargs)[source]#
Base class for actor costumes and world backgrounds.
Appearance is the parent class of both Costume and Background. You normally access it through actor.costume or world.background.
Examples
actor.costume.add_image("images/player.png") actor.costume.fill_color = (255, 0, 0) actor.costume.border = 2 actor.costume.is_animated = True actor.costume.alpha = 128
- LOAD_NEW_IMAGE = 2#
- RELOAD_ACTUAL_IMAGE = 1#
- add_images(sources)[source]#
Add multiple image sources.
Each source in sources must be a valid input for add_image.
Examples
actor.costume.add_images(["images/1.png", "images/2.png"])
- after_animation()[source]#
Hook called after a non-looping animation finishes.
Examples
@costume.register def after_animation(self): self.parent.remove()
- property alpha#
Transparency value of the appearance.
Use values from 0 to 255: - 0 means fully transparent - 255 means fully visible
If the value is between 0 and 1, it is interpreted as a normalized opacity and converted to the 0..255 range.
- animate(loop=False)[source]#
Start appearance animation.
- Parameters:
loop – Whether the animation should repeat.
Examples
actor.costume.add_images(["images/1.png", "images/2.png"]) actor.costume.animate(loop=True)
- animation_length#
- property animation_speed#
Frames between animation steps.
- property coloring#
Optional color layer.
Examples
actor.costume.coloring = (255, 0, 0)
- Type:
tuple | None
- counter = 0#
- draw_color_on_image(color, position, width, height)[source]#
Queue drawing a colored rectangle onto the appearance image.
- draw_images#
- draw_on_image(path, position, width, height)[source]#
Queue drawing an image file onto the appearance image.
- draw_shapes#
- property fill_color#
Primary fill color for shape-based rendering.
- font_manager#
- property font_size#
Current font size used for text rendering.
- from_array(arr)[source]#
Replace the appearance image from a color array.
- Parameters:
arr – NumPy color array, usually created with to_colors_array().
Examples
arr = world.background.to_colors_array() arr[0][0] = (255, 0, 0) world.background.from_array(arr)
- get_image()[source]#
If dirty, the image will be reloaded. The image pipeline will be processed, defined by “set_dirty”
- id#
-
image_manager:
ImageManager#
- property images#
List of image surfaces managed by this appearance.
- initialized#
- property is_animated#
Whether the appearance animates through its images.
Examples
actor.costume.add_images(["images/1.png", "images/2.png"]) actor.costume.animation_speed = 20 actor.costume.is_animated = True
- Type:
- property is_centered#
Whether drawing operations are centered on the parent position.
- property is_filled#
Whether shapes are rendered filled instead of outlined.
- property is_flipped#
Whether the image is mirrored horizontally.
Examples
actor.costume.is_flipped = True
- Type:
- property is_scaled#
Scales the token to parent-size without remaining aspect-ratio.
- property is_scaled_to_height#
Whether the image is scaled to parent height and keeps aspect ratio.
- property is_scaled_to_width#
Whether the image is scaled to parent width and keeps aspect ratio.
- property is_textured#
Whether the image is tiled over the parent area.
Examples
background = world.add_background("images/stone.png") background.is_textured = True background.texture_size = (15, 15)
- Type:
- property is_upscaled#
If True, the image will be upscaled remaining aspect-ratio.
- last_image#
- loop#
- property orientation#
Orientation offset applied before parent rotation.
Examples
actor.costume.orientation = -90
- Type:
- parent#
- set_dirty(value='all', status=1)[source]#
Mark pipeline stages as dirty so the image is re-rendered.
- set_image(source)[source]#
Set the displayed image.
- Return type:
- Parameters:
source – Image index, appearance, or color tuple.
- Returns:
True if the image index exists.
Examples
background.add_image("images/1.png") background.add_image("images/2.png") background.set_image(1)
- set_mode(**kwargs)[source]#
Set multiple appearance mode flags at once.
Supported keyword arguments include mode, texture_size, and animation_speed.
- surface_loaded#
- property texture_size#
Texture tile size used when is_textured is enabled.
- to_colors_array()[source]#
Return the appearance image as a color array.
- Return type:
ndarray- Returns:
A NumPy array containing color data.
Examples
arr = world.background.to_colors_array() arr[0][0] = (255, 0, 0) world.background.from_array(arr)
- transformations_manager#
- property transparency#
Whether alpha transparency is enabled.
The actual opacity is controlled by alpha.
- Type: