Appearance

Appearance is the base class for Costume and Background

The Appearance class contains all the logic common to both, e.g. scaling and rotating images. The child classes contain the actions that are specific to these classes (e.g. certain overlays).

All actions performed on the images can be found in the class ImageRenderer

Important

You do not need this class. If you work with tokens, then you use the child class Costume. If you work with the board, you use the child class Background.

classDiagram Appearance <|-- Costume Appearance <|-- Background Token o-- Appearance class Token{ +add_costume() } class Appearance{ +add_image(str) } class Costume{ } class Background{ }

Appearance

class miniworldmaker.appearances.appearance.Appearance(*args, **kwargs)[source]

Base class of token costumes and board backgrounds

The class contains all methods and attributes to display and animate images of the objects, render text on the images or display overlays.

add_image(path: str)int[source]

Adds an image to the appearance

Parameters
  • path – The path to the image relative to actual directory

  • animation – True if image should be removed after first animation

Returns: The index of the added image.

animation_speed

The animation speed for animations

blit(path, position: tuple, size: tuple = (0, 0))[source]

Blits an image to the background

Parameters
  • path – Path to the image

  • position – Top left position

  • size – Size of blitted image

Returns:

color

color for overlays

color_at(position: miniworldmaker.board_positions.board_position.BoardPosition)tuple[source]

Returns the color at a specific position

Parameters

position – The position to search for

Returns: The color

property coloring

Defines a colored layer. Coloring is True or false. The color is defined by the attribute appearance.color

count_pixels_by_color(rect, color, threshold=(0, 0, 0, 0))[source]

Counts the number of pixels of a color under the appearance.

Parameters
  • color – The color

  • threshold – The allowed deviation from the color splitted into r,g,b and alpha values.

Returns: The number of matching pixes

fill_color

background_color if actor has no background image

async first_image()[source]

Switches to the first image of the appearance.

property flip_vertical

If True, the image will be flipped l/r (e.g. for fighters in a street-fighter like game.

Examples

>>> class Player(miniworldmaker.Token):
>>>    def on_setup(self):
>>>         self.add_image("background_image.jpg")
>>>         self.costume.flip_vertical = True
Type

bool

font_path

Path to font-file

image_action_coloring(image: pygame.Surface, parent)pygame.Surface[source]

Create a “colorized” copy of a surface (replaces RGB values with the given color, preserving the per-pixel alphas of original).

Parameters
  • image – Surface to create a colorized copy of

  • newColor – RGB color to use (original alpha values are preserved)

Returns

New colorized Surface instance

property is_animated

If True, the image will be animated. Depends on appearance.animation_speed

Examples

>>> class Robot(Token):
>>>
>>> def __init__(self, position):
>>>     super().__init__(position)
>>>     self.add_image("images/robot_blue1.png")
>>>     self.add_image("images/robot_blue2.png")
>>>     self.size = (99, 99)
>>>     self.costume.animation_speed = 30
>>>     self.costume.is_animated = True
Type

bool

property is_flipped

Flips the token by 180° degrees.

This can be used e.g. for bouncing actor at border

Type

bool

property is_rotatable

If True, the image will be rotated by parent direction

Examples

>>> class Player(miniworldmaker.Token):
>>>    def on_setup(self):
>>>         self.add_image("background_image.jpg")
>>>         self.costume.is_rotatable = True
Type

bool

property is_scaled

Scales the actor to parent-size withour remaining aspect-ratio.

Type

bool

property is_textured

If True, the image is tiled over the background.

Examples

Defines a textured board

>>> class MyBoard(TiledBoard):
>>>    def on_setup(self):
>>>         self.add_image(path="images/stone.png")
>>>         self.background.is_textured = True
>>>         self.background.is_scaled_to_tile = True
>>>         self.player = Player(position=(3, 4))
Type

bool

property is_upscaled

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

Examples

>>> class Player(miniworldmaker.Token):
>>>    def on_setup(self):
>>>         self.add_image("background_image.jpg")
>>>         self.costume.is_upscaled = True
Type

bool

static load_image(path)[source]

Loads an image from an path.

Parameters

path – The path to image

Returns: The image loaded

async next_image()[source]

Switches to the next image of the appearance.

property orientation

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

Examples

>>> class Player(miniworldmaker.Token):
>>>    def on_setup(self):
>>>         self.add_image("background_image.jpg")
>>>         self.costume.orientation = -90
Type

bool

reload_image()[source]

Performs all actions in image pipeline

property text

Examples:

>>> explosion = Explosion(position=other.position.up(40).left(40))
>>> explosion.costume.is_animated = True
>>> explosion.costume.text_position = (100, 100)
>>> explosion.costume.text = "100"
text_position

Position of text relative to the top-left pixel of token