Actor > Widgets#
Verwenden Sie Button, wenn ein Widget einfach nur eine Nachricht senden soll.
Verwenden Sie SaveButton und LoadButton, wenn eine Welt mit einem Klick in einer SQLite-Datenbankdatei gespeichert oder daraus wiederhergestellt werden soll.
API-Referenz#
Etikett#
- class miniworlds.actors.widgets.label.Label(position: Tuple[float, float] | None = (0, 0), *args, **kwargs)[Quellcode]#
A text label for use in a
Toolbar.Labelis usually used for headings, status text, scores, or other information that should be shown inside a toolbar.- Parameter:
text – The text to display in the label.
image – Optional path to an image to show instead of (or alongside) text.
Beispiele
Add a label to a toolbar:
from miniworlds import * world = World(200, 200) toolbar = Toolbar() score_label = Label("Score: 0") toolbar.add(score_label) world.camera.add_right(toolbar) world.run()
Öffentliche Datenattribute:
Inherited from
Buttonfixed_widthchildrenactor_countclass_imageInherited from
SingleWidgetpadding_leftpadding_rightpadding_toppadding_bottompositionThe position of the actor as Position(x, y)
topleftTop-left position of the actor in world coordinates.
centerCenter position of the actor in world coordinates.
row_heighttext_alignDefines how text is aligned.
textThe text which is displayed on the widget.
fixed_widthchildrenactor_countclass_imageInherited from
BaseWidgetpadding_leftpadding_rightpadding_toppadding_bottompositionThe position of the actor as Position(x, y)
topleftTop-left position of the actor in world coordinates.
centerCenter position of the actor in world coordinates.
row_heightfixed_widthchildrenactor_countclass_imageInherited from
ParentActorvisibleWhether the actor is currently visible.
layerDefines the layer on which the actor is drawn if several actors overlap.
childrenactor_countclass_imageInherited from
ActorCurrent origin mode used for size and position operations.
collision_type gibt an, wie Kollisionen überprüft werden sollen:
A actor with the property
is_blockablecannot move through actors with the propertyis_blocking.A actor with the property
is_blockablecannot move through actors with the propertyis_blocking.Defines the layer on which the actor is drawn if several actors overlap.
Actor-Position im letzten Frame
Direction value from the previous frame.
Returns number of costumes of actor, 0 if actor has no costume
Whether the actor costume is mirrored on the horizontal axis.
Gets the costume of the actor, if available.
Ruft den Kostümmanager ab
Costume orientation offset in degrees.
Directions are handled exactly as in the Scratch programming language, see: Scratch Wiki
Gibt die Richtung als Wert im Einheitskreis an (0° rechts, 90° oben, 180° links…)
Größe des Actors
Die Breite des Actors in Pixeln.
Die Höhe des Actors in Pixeln.
Der x-Wert eines Actors
Der y-Wert eines Actors
Class name of this actor instance.
x-Wert der oberen linken Position des Actors
y-value of actor topleft-position
Top-left position of the actor in world coordinates.
x-Wert der Actor-Mittelposition innerhalb des aktuellen Kamerabildschirms
x-Wert der Mittelpunktposition des Actors
y-Wert der Mittelpunktposition des Actors
Center position of the actor in world coordinates.
Legt fest, ob das Kostüm eines Actors drehbar sein soll.
Should actor react to events? You can turn this option off for additional performance boost.
Fill color of the actor as RGBA tuple.
Fill color of the actor as RGBA tuple.
Ist der Actor mit Farbe gefüllt?
Border color as RGBA tuple.
Border color as RGBA tuple.
Border width of the actor.
Whether the actor is currently visible.
World this actor belongs to.
Das Bild des Actors:
The position of the actor as Position(x, y)
Inherited from
ActorBasedirtyWenn der Actor schmutzig ist, wird er neu gezeichnet.
rectDas umgebende Rechteck als pygame.Rect.
position_managersensor_managercostume_managerInherited from
DirtySpritevisibleYou can make this sprite disappear without removing it from the group assign 0 for invisible and 1 for visible
layerLayer property can only be set before the sprite is added to a group, after that it is read only and a sprite's layer in a group should be set via the group's change_layer() method.
Inherited from
SpriteimagerectlayerDynamic, read only property for protected _layer attribute.
Öffentliche Methoden:
__init__(text[, image])Creates a label widget.
Inherited from
Button__init__([text, image])Creates a toolbar button.
on_clicked_left(mouse_pos)Called when the button is clicked.
act()Counts down the short click cooldown.
Inherited from
SingleWidget__init__([position])resize()cut_widget_text()update_positions()get_local_pos(position)set_row_height([value])set_border([color, width])Sets the widget border color and width.
set_position(value)Set actor position in world coordinates.
set_world(new_world)Move the actor to another world and return the actor.
get_widget_text()set_image(_img_source)sets image of widget
set_text(text)Sets text of widget.
get_text()Inherited from
BaseWidget__init__([position])new_costume()Create and attach a new empty costume to this actor.
resize()update_positions()get_local_pos(position)set_row_height(value)set_border([color, width])Sets the widget border color and width.
set_world(new_world)Move the actor to another world and return the actor.
set_position(value)Set actor position in world coordinates.
Inherited from
ParentActor__init__(position[, children])add_child(actor)set_layer(value)set_world(new_world)Move the actor to another world and return the actor.
reset_costumes()Remove all costumes and reset appearance state.
before_remove()Hook called immediately before the actor is removed from the world.
Inherited from
Actor__init__([position])switch_origin(value)Switch actor origin while preserving the visual on-screen position.
create_on_world(world)Creates a actor to a specific world
from_topleft(topleft_position, *args, **kwargs)Create an actor whose origin is interpreted as top-left.
from_center(center_position, *args, **kwargs)Create an actor whose origin is interpreted as center.
flip_x()Dreht den Actor um 180° Grad.
add_costume([source])Adds a new costume to actor.
add_costumes(sources)Adds multiple costumes
remove_costume([source])Removes a costume from actor
switch_costume(source)Switches the costume of actor
set_costume(costume)Set the current costume from an index, source, or appearance object.
Remove all costumes and reset appearance state.
set_background_color(color)Set a background color behind the actor costume image.
Switches to the next costume of actor
Return True when the actor currently has a costume.
turn_left([degrees])Turns actor by degrees degrees left :rtype:
intturn_right([degrees])Turns actor by degrees degrees right
set_direction(direction)Actor points in given direction.
point_towards_position(destination)Actor points towards a given position
point_towards_actor(other)Actor points towards another actor.
set_size(value)Set actor size as (width, height) in pixels.
scale_width(value)Scale actor width by a factor.
scale_height(value)Scale actor height by a factor.
move([distance, direction])Moves actor distance steps in current direction
move_vector(vector)Moves actor in direction defined by the vector
move_back(distance)Moves the actor backward by distance steps (opposite of current direction).
Machen Sie den letzten Zug rückgängig.
move_towards(target)Move one step toward a target actor or position.
move_in_direction(direction[, distance])Bewegt den Actor distance Schritte in eine direction oder zu einer Position
move_to(position)Bewegt den Actor distance zu einer bestimmten world_posiition
remove([kill])Entfernt diesen Actor aus der Welt
Hook called immediately before the actor is removed from the world.
bounce_from_border(borders)Der Actor prallt von einem Rand ab.
detect_all([actors, direction, distance])Detects if actors are on actor position.
detect(*args, **kwargs)Detects if actors are on actor position.
detect_borders([distance])Detects borders
Does the actor touch the left border?
Does the actor touch the right border?
Does the actor touch the top border?
Does the actor touch the lower border?
detect_color([color])Detects colors in world-background at actor center-position
detect_color_at([direction, distance])Detects colors in world-background at actor-position
detect_actors_at([direction, distance, actors])Detects a actor in given direction and distance.
detect_actor_at([direction, distance, actors])Detect and return the first actor at a given direction and distance.
detect_actors_in_front([actors, distance])Detect all actors directly in front of this actor.
detect_actor_in_front([actors, distance])Detect and return the first actor directly in front.
detect_point(position)Is the actor colliding with a specific (global) point?
detect_pixel(position)Is the actor colliding with a pixel?
detect_rect(rect)Is the actor colliding with a static rect?
Checks whether the actor is completely inside the world boundaries.
bounce_from_actor(other)Reflect movement direction when colliding with another actor.
animate([speed])Animate the current costume with the given speed.
animate_costume(costume[, speed])Animate a specific costume with the given speed.
animate_loop([speed])Animates a costume with a looping animation
Stops current animation.
send_message(message)Sends a message to world.
on_key_down(key)Called once when a key is pressed.
on_key_pressed(key)Called repeatedly every frame while a key is held down.
on_key_up(key)Called once when a previously pressed key is released.
on_mouse_over(position)Called when the mouse cursor enters or moves over the actor area.
on_mouse_leave(position)Called when the mouse cursor leaves the actor area.
on_mouse_left_down(position)Called when the left mouse button is pressed down.
on_mouse_right_down(position)Called when the right mouse button is pressed down.
on_mouse_left(position)Called when the left mouse button is clicked.
on_mouse_right(position)Called when the right mouse button is clicked.
on_mouse_motion(position)Called when the mouse moves.
on_mouse_left_released(position)Method is called when left mouse key is released.
on_mouse_right_released(position)Method is called when right mouse key is released.
on_clicked_left(position)The mouse is on top of a actor and mouse was clicked.
on_clicked_right(position)The mouse is on top of a actor and mouse was clicked.
on_detecting_world is called, when actor is on the world
Called when the actor is not touching the world (i.e. outside world bounds).
on_detecting_actor(actor)on_detecting_actor is called, when actor is detects a actor on same position
on_detecting_borders(borders)on_detecting_border wird aufgerufen, wenn sich der Actor in der Nähe einer Grenze befindet
fill(value)Füllfarbe für Ränder und Linien festlegen
hide()Verbirgt einen Actor (der Actor wird unsichtbar)
show()Zeigt einen Actor an (ein unsichtbarer Actor wird sichtbar)
register_sensor(*args, **kwargs)This method is used for the @register_sensor decorator.
Return actor rect in camera-local coordinates.
set_world(new_world)Move the actor to another world and return the actor.
Create and attach a new empty costume to this actor.
set_position(value)Set actor position in world coordinates.
get_distance_to(obj)Gets the distance to another actor or a position
Hook called when actor shape-related properties change.
Inherited from
ActorBaseregister(method[, force, name])This method is used for the @register decorator.
register_message(*args, **kwargs)Registriert eine Methode bei einem Objekt, um bestimmte
on_message-Ereignisse zu behandeln.__str__()Gib str(self) zurück.
get_costume_class()Inherited from
DirtySprite__init__(*groups)__repr__()Gib repr(self) zurück.
Inherited from
Sprite__init__(*groups)add(*groups)füge den Sprite zu Gruppen hinzu
remove(*groups)entferne den Sprite aus den Gruppen
add_internal(group)Um diesen Sprite intern zu einer Gruppe hinzuzufügen.
remove_internal(group)For removing this sprite from a group internally.
update(*args, **kwargs)method to control sprite behavior
kill()entferne den Sprite aus allen Gruppen
groups()Liste der Gruppen, die diesen Sprite enthalten
alive()gehört der Sprite zu irgendwelchen Gruppen
__repr__()Gib repr(self) zurück.
Private Datenattribute:
_abc_implInherited from
Button_abc_impl_visible_layer__image__rectInherited from
SingleWidget_abc_impl_visible_layer__image__rectInherited from
BaseWidget_abc_impl_visible_layer__image__rectInherited from
ParentActor_abc_impl_visible_layer__image__rectInherited from
Actor_abc_impl__image__rectInherited from
ActorBase_abc_impl__image__rectPrivate Methoden:
Inherited from
Actor_get_initialization_facade()_get_appearance_facade()_get_event_facade()_get_sensor_facade()_get_movement_facade()_get_size_facade()_validate_arguments(position, *args, **kwargs)Inherited from
ActorBase_is_actor_repainted()Inherited from
DirtySprite_set_visible(val)den sichtbaren Wert (0 oder 1) festlegen und den Sprite als verändert markieren
_get_visible()den sichtbaren Wert dieses Sprites zurückgeben
- __init__(text, image=None)[Quellcode]#
Creates a label widget.
- Parameter:
text – The text displayed by the label.
image – Optional image path.