Costumes and Backgrounds

The Costume and Background classes are child classes of the Appearance class.

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

Inheritance diagram of miniworldmaker.appearances.background.Background, miniworldmaker.appearances.costume.Costume

Appearance

class miniworldmaker.appearances.appearance.Appearance[source]

Base class of token costumes and board backgrounds

Die Klasse enthält alle Methoden und Attribute um Bilder der Objekte anzuzeigen, zu animieren, Text auf den Bildern zu rendern oder Overlays anzuzeigen.

add_image(path: str) → int[source]

Adds an image to the appearance

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

  • crop – tuple: x,y,width, height

Returns: The index of the added image.

animation_speed = None

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 = None

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

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 = None

background_color if actor has no background image

font_path = None

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

is_animated

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

Type

bool

is_flipped

Flips the token by 180° degrees.

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

Type

bool

is_rotatable

If True, the image will be rotated by parent direction

Type

bool

is_scaled

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

Type

bool

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

is_upscaled

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

Type

bool

static load_image(path)[source]

Loads an image from an path.

Parameters

path – The path to image

Returns: The image loaded

next_image()[source]

Switches to the next image of the appearance.

orientation

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

This should be used, if image is not pointing to right direction

Type

bool

text

If text!= “” a Text is rendered at the token-position.

text_position = None

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

Background

class miniworldmaker.appearances.background.Background(board)[source]

The class describes the background of a board.

Each board has one or more backgrounds that can be switched between. In addition, each background also has several pictures between which you can switch.

You can scale a background or tile it like a texture.

grid_overlay

If not False, a grid overlay is drawn over the background image.

Examples

>>> a_token.background.grid_overlay = (255, 0, 0, 0)
Draws a red (255, 0, 0, 0) background overlay
>>> a_token.background.grid_overlay = False
Disables background grid_overlay
>>> a_token.background.grid_overlay = ()
Disables background grid_overlay. Same as a_token.background.grid_overlay = False
is_scaled_to_tile

Scales the image to Tile_size.

The method is needed if you want to texture the background on a Tiled_Board and want the texture to fill one tile at a time.

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))
next_image()[source]

Switches to the next image of the appearance.

parent = None

The parent of a Background is the associated board.

Costume

class miniworldmaker.appearances.costume.Costume(token)[source]

A costume contains one or multiple images

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

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

parent = None

the parent of a costume is the associated token.