Appearance

Inhalt

Appearance#

Appearance ist die Basisklasse von Background und Costume.

Backgrounds und Costumes sind ebenfalls Appearances und erben daher alle in dieser Klasse definierten Attribute und Methoden.

API-Referenz#

class miniworlds.appearances.appearance.Appearance(*args, **kwargs)[Quellcode]#

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.

Beispiele

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_image(source)[Quellcode]#

Fügt eine Bildquelle hinzu und gibt ihren Index zurück.

Rückgabetyp:

int

add_images(sources)[Quellcode]#

Füge mehrere Bildquellen hinzu.

Each source in sources must be a valid input for add_image.

Beispiele

actor.costume.add_images(["images/1.png", "images/2.png"])
after_animation()[Quellcode]#

Hook, der nach dem Ende einer nicht wiederholten Animation aufgerufen wird.

Beispiele

@costume.register
def after_animation(self):
    self.parent.remove()
after_init()[Quellcode]#

Schließt die Initialisierung nach dem Konstruktor-Hook der Metaklasse ab.

property alpha#

Transparenzwert der Darstellung.

Verwende Werte von 0 bis 255: - 0 bedeutet vollständig transparent - 255 bedeutet vollständig sichtbar

Liegt der Wert zwischen 0 und 1, wird er als normalisierte Deckkraft interpretiert und in den Bereich 0…255 umgerechnet.

animate(loop=False)[Quellcode]#

Start appearance animation.

Parameter:

loop – Ob die Animation wiederholt werden soll.

Beispiele

actor.costume.add_images(["images/1.png", "images/2.png"])
actor.costume.animate(loop=True)
animation_length#
property animation_speed#

Anzahl der Frames zwischen Animationsschritten.

property border#

Rahmenbreite in Pixeln.

A value of 0 means no border.

Typ:

int

property border_color#

Rahmenfarbe.

Typ:

tuple

property color#

Alias für fill_color.

Typ:

tuple

property coloring#

Optionale Farbschicht.

Beispiele

actor.costume.coloring = (255, 0, 0)
Typ:

tuple | None

counter = 0#
draw(source, position, width, height)[Quellcode]#

Zeichnet eine Bildquelle an einer lokalen Position.

draw_color_on_image(color, position, width, height)[Quellcode]#

Plant das Zeichnen eines farbigen Rechtecks auf das Appearance-Bild ein.

draw_image_append(surface, rect)[Quellcode]#

Hängt einen Zeichenbefehl für eine vorgerenderte Surface an.

draw_image_set(surface, rect)[Quellcode]#

Ersetzt Bild-Zeichenbefehle durch einen einzelnen Surface-Zeichenbefehl.

draw_images#
draw_on_image(path, position, width, height)[Quellcode]#

Plant das Zeichnen einer Bilddatei auf das Appearance-Bild ein.

draw_shape_append(shape, arguments)[Quellcode]#

Hängt einen Form-Zeichenbefehl an die Render-Warteschlange an.

draw_shape_set(shape, arguments)[Quellcode]#

Ersetzt Form-Zeichenbefehle durch einen einzelnen Befehl.

draw_shapes#
fill(value)[Quellcode]#

Setzt die Standard-Füllfarbe für Rahmen und Linien.

property fill_color#

Primäre Füllfarbe für formbasiertes Rendering.

flip(value)[Quellcode]#

Hilfsmethode zum Setzen von is_flipped.

font_manager#
property font_size#

Aktuelle Schriftgröße für das Rendern von Text.

from_array(arr)[Quellcode]#

Ersetzt das Bild der Darstellung durch ein Farbarray.

Parameter:

arr – NumPy-Farbarray, üblicherweise mit to_colors_array() erstellt.

Beispiele

arr = world.background.to_colors_array()
arr[0][0] = (255, 0, 0)
world.background.from_array(arr)
get_color(position)[Quellcode]#

Gibt die Farbe an einer lokalen Pixelposition zurück.

get_image()[Quellcode]#

Wenn verschmutzt, wird das Bild neu geladen. Die Bildpipeline wird verarbeitet, definiert durch “set_dirty”

abstract get_manager()[Quellcode]#

In Unterklassen Kostüm und Hintergrund implementiert

get_modes()[Quellcode]#

Gibt alle Modus-Flags als Dictionary zurück.

get_rect()[Quellcode]#

Gibt das lokale Rechteck des gerenderten Bildes zurück.

id#
image_manager: ImageManager#
property images#

Liste der von dieser Appearance verwalteten Bild-Surfaces.

initialized#
property is_animated#

Ob die Darstellung durch ihre Bilder animiert wird.

Beispiele

actor.costume.add_images(["images/1.png", "images/2.png"])
actor.costume.animation_speed = 20
actor.costume.is_animated = True
Typ:

bool

property is_centered#

Ob Zeichenoperationen auf der Elternposition zentriert sind.

property is_filled#

Ob Formen gefüllt statt nur als Kontur gerendert werden.

property is_flipped#

Ob das Bild horizontal gespiegelt wird.

Beispiele

actor.costume.is_flipped = True
Typ:

bool

property is_rotatable#

Whether the image rotates with the parent direction.

Typ:

bool

property is_scaled#

Skaliert das Token auf die Größe des übergeordneten Elements, ohne das Seitenverhältnis beizubehalten.

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.

Beispiele

background = world.add_background("images/stone.png")
background.is_textured = True
background.texture_size = (15, 15)
Typ:

bool

property is_upscaled#

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

last_image#
loop#
property orientation#

Ausrichtungsversatz, der vor der Rotation des übergeordneten Objekts angewendet wird.

Beispiele

actor.costume.orientation = -90
Typ:

float

parent#
register(method)[Quellcode]#

Registriere Methode für Dekorator. Registriert Methode für Actor oder Hintergrund.

remove_last_image()[Quellcode]#

Entfernt das zuletzt hinzugefügte Bild.

set_animated(value)[Quellcode]#

Aktiviert oder deaktiviert framebasierte Animation.

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

Markiert Pipeline-Stufen als dirty, damit das Bild neu gerendert wird.

set_filled(value)[Quellcode]#

Legt fest, ob Formen gefüllt gerendert werden.

set_image(source)[Quellcode]#

Setzt das angezeigte Bild.

Rückgabetyp:

bool

Parameter:

source – Bildindex, Darstellung oder Farbtupel.

Rückgabe:

True if the image index exists.

Beispiele

background.add_image("images/1.png")
background.add_image("images/2.png")
background.set_image(1)
set_mode(**kwargs)[Quellcode]#

Setzt mehrere Appearance-Modus-Flags auf einmal.

Unterstützte Schlüsselwortargumente sind mode, texture_size und animation_speed.

property stroke_color#

Alias für border_color.

Typ:

tuple

surface_loaded#
property texture_size#

Kachelgröße der Textur, wenn is_textured aktiviert ist.

to_colors_array()[Quellcode]#

Return the appearance image as a color array.

Rückgabetyp:

ndarray

Rückgabe:

Ein NumPy-Array mit Farbdaten.

Beispiele

arr = world.background.to_colors_array()
arr[0][0] = (255, 0, 0)
world.background.from_array(arr)
transformations_manager#
property transparency#

Ob Alpha-Transparenz aktiviert ist.

Die tatsächliche Deckkraft wird über alpha gesteuert.

Typ:

bool

abstract property world: World#

In Unterklassen Kostüm und Hintergrund implementiert