World > Hintergrund#

A Background is a child class of the Appearance-Class. Most of it’s methods and attributes you can therefore find in the baseclass Appearance

Hintergrund#

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

Die Klasse beschreibt den Hintergrund einer Welt.

Ein Hintergrund kann ein Bild oder eine Farbe sein:

Jede Welt hat einen oder mehrere Hintergründe, zwischen denen man wechseln kann. Darüber hinaus hat jeder Hintergrund auch mehrere Bilder (oder Farben), zwischen denen man wechseln kann.

Beispiele

Fügen Sie ein Bild als Hintergrund hinzu

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

Fügen Sie eine Farbe als Hintergrund hinzu:

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

…oder alternative Möglichkeit: Erstellen Sie einen Hintergrund mit der Eigenschaft:

from miniworlds import *

world = World()
world.background =(255,0,0)
world.run()

Öffentliche Datenattribute:

world

In Unterklassen Kostüm und Hintergrund implementiert

grid

Zeigt ein Raster-Overlay

parent

Background.parent Die Welt, zu der der Hintergrund gehört

image_manager

Inherited from Appearance

counter

RELOAD_ACTUAL_IMAGE

LOAD_NEW_IMAGE

font_size

texture_size

animation_speed

is_textured

If True, the image is tiled over the background.

is_rotatable

If True, costume will be rotated with token direction

is_centered

is_filled

is_flipped

Flips the costume or background.

is_upscaled

Wenn True, wird das Bild unter Beibehaltung des Seitenverhältnisses hochskaliert.

is_scaled_to_width

is_scaled_to_height

fill_color

is_scaled

Skaliert das Token auf die Größe des übergeordneten Elements ohne Beibehaltung des Seitenverhältnisses.

orientation

Wenn True, wird das Bild vor der Drehung entsprechend der Ausrichtung des übergeordneten Elements gedreht.

coloring

Defines a colored layer.

transparency

Defines a transparency.

alpha

transparent, 255: visible If value < 1, it will be multiplied with 255.

is_animated

If True, the costume will be animated.

color

->Füllfarbe anzeigen

stroke_color

see border color

border_color

border color of actor

border

Die Randgröße des Actors.

images

image

Führt alle Aktionen in der Bildpipeline aus

dirty

world

In Unterklassen Kostüm und Hintergrund implementiert

image_manager

Public Methods:

__init__([world])

set_dirty([value, status])

get_manager()

In Unterklassen Kostüm und Hintergrund implementiert

show_grid()

repaint()

Called 1/frame from world

add_image(source)

Adds an image to the appearance

get_rect()

Inherited from Appearance

__init__()

set_image(source)

Setzt das angezeigte Bild des Kostüms/Hintergrunds auf den ausgewählten Index

after_init()

set_mode(**kwargs)

get_modes()

set_animated(value)

flip(value)

remove_last_image()

add_image(source)

Adds an image to the appearance

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)

get_color(position)

get_rect()

draw(source, position, width, height)

draw_on_image(path, position, width, height)

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

__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)

draw_shape_set(shape, arguments)

draw_image_append(surface, rect)

draw_image_set(surface, rect)

set_dirty([value, status])

get_manager()

In Unterklassen Kostüm und Hintergrund implementiert

Private Data Attributes:

_abc_impl

Inherited from Appearance

_abc_impl

Private Methods:

_after_transformation_pipeline()

Aufgerufen in get_image, wenn das Bild “dirty” ist (z.B. Größe, Drehung, .

_blit_to_window_surface()

Blits background to window surface

_inner_shape()

Returns inner shape of costume

_outer_shape()

Returns outer shape of costume

Inherited from Appearance

_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)

Flips the costume or background.

_set_scaled(value)

Setzt den Actor auf die Eltern-Größe ohne das Seitenverhältnis beizubehalten.

_set_upscaled(value)

Wenn auf True gesetzt, wird das Bild unter Beibehaltung des Seitenverhältnisses hochskaliert.

_set_scaled_to_width(value)

_set_scaled_to_height(value)

_set_image(source)

Setzt das angezeigte Bild des Kostüms/Hintergrunds auf den ausgewählten Index

_before_transformation_pipeline()

Aufgerufen in get_image, wenn das Bild “dirty” ist (z.B. Größe, Drehung, .

_after_transformation_pipeline()

Aufgerufen in get_image, wenn das Bild “dirty” ist (z.B. Größe, Drehung, .

_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()

def setGets arguments for inner shape

_outer_shape_arguments()

Gets arguments for outer shape


add_image(source)[Quellcode]#

Adds an image to the appearance

Rückgabetyp:

int

Rückgabe:

Index des erstellten Bildes.

get_manager()[Quellcode]#

In Unterklassen Kostüm und Hintergrund implementiert

get_rect()[Quellcode]#
property grid: bool | tuple#

Zeigt ein Raster-Overlay

grid kann True, False oder ein Farb-Tupel sein

Beispiele

Raster anzeigen:

from miniworlds import *

world = TiledWorld(4,4)
world.tile_margin = 10
background = world.add_background("images/stone.png")
background.is_textured = True
actor = Actor()
@actor.register
def on_key_down(self, key):
    self.move_right()
background.grid = True
world.run()
Texturiertes Bild
parent: world_mod.World#

Background.parent Die Welt, zu der der Hintergrund gehört

repaint()[Quellcode]#

Called 1/frame from world

set_dirty(value='all', status=1)[Quellcode]#
show_grid()[Quellcode]#
property world: World#

In Unterklassen Kostüm und Hintergrund implementiert