Actor > Costume#

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

API Reference#

class miniworlds.appearances.costume.Costume(*args, **kwargs)[source]#

A costume contains one or multiple images

Every actor has a costume which defines the “look” of the actor. You can switch the images in a costume to animate the actor.

A costume is created if you add an image to an actor with actor.add_image(path_to_image)

Public Data Attributes:

world

Owning world of this costume.

info_overlay

Shows info overlay (Rectangle around the actor and Direction marker)

image_manager

Inherited from Appearance

counter

RELOAD_ACTUAL_IMAGE

LOAD_NEW_IMAGE

font_size

Current font size used for text rendering.

texture_size

Texture tile size used when is_textured is enabled.

animation_speed

Frames between animation steps.

is_textured

If True, the image is tiled over the background.

is_rotatable

If True, costume will be rotated with token direction

is_centered

Whether drawing operations are centered on the parent position.

is_filled

Whether shapes are rendered filled instead of outlined.

is_flipped

Flips the costume or background.

is_upscaled

If True, the image will be upscaled remaining aspect-ratio.

is_scaled_to_width

Whether the image is scaled to parent width and keeps aspect ratio.

is_scaled_to_height

Whether the image is scaled to parent height and keeps aspect ratio.

fill_color

Primary fill color for shape-based rendering.

is_scaled

Scales the token to parent-size without remaining aspect-ratio.

orientation

If True, the image will be rotated by parent orientation before it is rotated.

coloring

Defines a colored layer.

transparency

Defines a transparency.

alpha

Transparency value of the appearance.

is_animated

If True, the costume will be animated.

color

->See fill color

stroke_color

see border color

border_color

border color of actor

border

The border-size of actor.

images

List of image surfaces managed by this appearance.

image

Performs all actions in image pipeline

dirty

Dirty flag for the current rendering pipeline state.

world

Implemented in subclasses Costume and Background

image_manager

Public Methods:

__init__(actor)

get_manager()

Return the owning costume manager of the actor.

after_init()

Apply actor and world defaults after construction.

set_image(source)

rotated()

Mark rotation-dependent rendering as dirty after actor rotation.

origin_changed()

Mark rendering as dirty after an origin change.

resized()

Mark scaling-dependent rendering as dirty.

visibility_changed()

Mark full rendering as dirty after visibility updates.

set_dirty([value, status])

Set dirty flags and keep actor rect/mask caches in sync.

get_rect()

Return a frame-cached local rect for the rendered costume image.

Inherited from Appearance

__init__()

set_image(source)

Sets the displayed image of costume/background to selected index

after_init()

Finalize initialization after the metaclass constructor hook.

set_mode(**kwargs)

Set multiple appearance mode flags at once.

get_modes()

Return all mode flags as a dictionary.

set_animated(value)

Enable or disable frame-based animation.

flip(value)

Convenience wrapper to set is_flipped.

remove_last_image()

Remove the most recently added image.

add_image(source)

Add an image source and return its index.

add_images(sources)

Adds multiple images to background/costume.

animate([loop])

Animates the costume

after_animation()

the method is overwritten in subclasses costume and appearance

to_colors_array()

Create an array from costume or background.

from_array(arr)

Create a background or costume from array.

fill(value)

Set default fill color for borders and lines

set_filled(value)

Set whether shapes are rendered filled.

get_color(position)

Return the color at a local pixel position.

get_rect()

Return the local rectangle of the rendered image.

draw(source, position, width, height)

Draw an image source at a local position.

draw_on_image(path, position, width, height)

Queue drawing an image file onto the appearance image.

draw_color_on_image(color, position, width, ...)

Queue drawing a colored rectangle onto the appearance image.

__str__()

Return str(self).

get_image()

If dirty, the image will be reloaded.

update()

Loads the next image, called 1/frame

register(method)

Register method for decorator.

draw_shape_append(shape, arguments)

Append a shape draw command to the render queue.

draw_shape_set(shape, arguments)

Replace shape draw commands with a single command.

draw_image_append(surface, rect)

Append a pre-rendered surface draw command.

draw_image_set(surface, rect)

Replace image draw commands with one surface draw command.

set_dirty([value, status])

Mark pipeline stages as dirty so the image is re-rendered.

get_manager()

Implemented in subclasses Costume and Background

Private Data Attributes:

_abc_impl

Inherited from Appearance

_abc_impl

Private Methods:

_set_default_color_values()

_set_actor_default_values()

_set_world_default_values()

_inner_shape()

Returns inner shape of costume

_outer_shape()

Returns outer shape of costume

Inherited from Appearance

_get_rendering_facade()

_set_defaults(**kwargs)

_set_font(font, font_size)

_set_animation_speed(value)

_set_textured(value)

bool: If True, the image is tiled over the background.

_set_rotatable(value)

If set to True, costume will be rotated with actor direction

_set_centered(value)

_set_flipped(value)

Flips the costume or background.

_set_filled(value)

Sets whether the costume or background should be filled with a color.

_set_scaled(value)

Sets the actor to parenz-size without remaining aspect-ratio.

_set_upscaled(value)

If set to True, the image will be upscaled remaining aspect-ratio.

_set_scaled_to_width(value)

_set_scaled_to_height(value)

_set_image(source)

Sets the displayed image of costume/background to selected index

_before_transformation_pipeline()

Called in get_image before the image transformation pipeline is processed (e.g. when size, rotation, or other display properties have changed).

_after_transformation_pipeline()

Called in get_image after the image transformation pipeline is processed (e.g. when size, rotation, or other display properties have changed).

_load_image()

Loads the image,

_update_draw_shape()

_inner_shape()

Returns inner shape of costume

_outer_shape()

Returns outer shape of costume

_inner_shape_arguments()

Gets arguments for inner shape.

_outer_shape_arguments()

Gets arguments for outer shape


after_init()[source]#

Apply actor and world defaults after construction.

get_manager()[source]#

Return the owning costume manager of the actor.

get_rect()[source]#

Return a frame-cached local rect for the rendered costume image.

property info_overlay#

Shows info overlay (Rectangle around the actor and Direction marker)

origin_changed()[source]#

Mark rendering as dirty after an origin change.

parent#

the parent of a costume is the associated actor.

resized()[source]#

Mark scaling-dependent rendering as dirty.

rotated()[source]#

Mark rotation-dependent rendering as dirty after actor rotation.

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

Set dirty flags and keep actor rect/mask caches in sync.

set_image(source)[source]#
Parameters:

source – index, Appearance or color.

Returns:

True if image exists

visibility_changed()[source]#

Mark full rendering as dirty after visibility updates.

property world: World#

Owning world of this costume.