World > Background#
Ein Background ist eine Kindklasse der Appearance-Klasse. Die meisten Funktionen findest du daher dort.
Background#
- class miniworlds.appearances.background.Background(*args, **kwargs)[source]#
The class describes the background of a world.
A
background
can be an image or a color:Each world has one or more backgrounds that can be switched between. In addition, each background also has several pictures (or colors) between which you can switch.
Examples
Add an image as background
world = World() World.add_background(images/my_image.png)
Add a color as background:
world = World() World.add_background((255, 0,0, 0))
..or alternative way: Create background with property:
from miniworlds import * world = World() world.background =(255,0,0) world.run()
Public Data Attributes:
Implemented in subclasses Costume and Background
Shows a grid-overlay
Background.parent The world to which the background belongs to
image_manager
Inherited from
Appearance
If True, the image is tiled over the background.
If True, costume will be rotated with token direction
Flips the costume or background.
If True, the image will be upscaled remaining aspect-ratio.
Scales the token to parent-size without remaining aspect-ratio.
If True, the image will be rotated by parent orientation before it is rotated.
Defines a colored layer.
Defines a transparency.
transparent, 255: visible If value < 1, it will be multiplied with 255.
If True, the costume will be animated.
->See fill color
see border color
border color of actor
The border-size of actor.
Performs all actions in image pipeline
Implemented in subclasses Costume and Background
Public Methods:
__init__
([world])set_dirty
([value, status])repaint
()Called 1/frame from world
add_image
(source)Adds an image to the appearance
Inherited from
Appearance
__init__
()set_image
(source)Sets the displayed image of costume/background to selected index
set_mode
(**kwargs)set_animated
(value)flip
(value)add_image
(source)Adds an image to the appearance
add_images
(sources)Adds multiple images to background/costume.
animate
([loop])Animates the costume
the method is overwritten in subclasses costume and appearance
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).
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])Private Methods:
_after_transformation_pipeline
()Called in get_image, if image is "dirty" (e.g. size, rotation, .
_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
(rotatable, is_animated, ...)_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)Sets the actor to parenz-size without remaining aspect-ratio.
_set_upscaled
(value)If set to True, the image will be upscaled remaining aspect-ratio.
_set_scaled_to_width
(value)_set_scaled_to_height
(value)_set_image
(source)Sets the displayed image of costume/background to selected index
_before_transformation_pipeline
()Called in get_image, if image is "dirty" (e.g. size, rotation, .
_after_transformation_pipeline
()Called in get_image, if image is "dirty" (e.g. size, rotation, .
_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)[source]#
Adds an image to the appearance
- Return type:
- Returns:
Index of the created image.
- property grid: bool | tuple#
Shows a grid-overlay
grid can be True, False or a color-tuple
Examples
Show grid:
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()
- parent: world_mod.World#
Background.parent The world to which the background belongs to