Appearance: Background
Contents
Appearance: Background¶
The ‘Background’ class is a child classes of the ‘Appearance’ class.
Note
Usually backgrounds are created with board.add_background([image_path|color])
Background¶
- class miniworldmaker.appearances.background.Background(*args, **kwargs)[source]¶
The class describes the background of a board.
A
background
can be an image or a color:Each board 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
board = Board() Board.add_background(images/my_image.png)
Add a color as background:
board = Board() Board.add_background((255, 0,0, 0))
..or alternative way: Create background with property:
from miniworldmaker import * board = Board() board.background =(255,0,0) board.run()
Public Data Attributes:
Shows a grid-overlay
Inherited from : py: class:Appearance
font_size
is_textured
If True, the image is tiled over the background.
is_rotatable
If True, costume will be rotated with token direction
is_centered
orientation
If True, the image will be rotated by parent orientation before it is rotated.
is_flipped
Flips the costume or background.
is_scaled
Scales the actor to parent-size without remaining aspect-ratio.
is_upscaled
If True, the image will be upscaled remaining aspect-ratio.
is_scaled_to_width
is_scaled_to_height
fill_color
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
->See fill color
is_filled
Is token filled with color?
stroke_color
see border color
border_color
border color of token
border
The border-size of token.
Inherited from : py: class:AppearanceBase
counter
RELOAD_ACTUAL_IMAGE
LOAD_NEW_IMAGE
dirty
image
Performs all actions in image pipeline
text
Examples:
images
Public Methods:
__init__
([board])repaint
()Called 1/frame from board
add_image
(source)Adds an image to the appearance
Inherited from : py: class:Appearance
set_font
(font, font_size)set_animation_speed
(value)flip
(value)get_text_width
()remove_last_image
()add_image
(source)Adds an image to the appearance
add_images
(sources)Adds multiple images to background/costume.
count_pixels_by_color
(rect, color[, threshold])Counts the number of pixels of a color under the appearance.
animate
()Animates the costume
after_animation
()the method is overwritten in subclasses costume and appearance
reset
()set_image
(source)Sets the displayed image of costume/background to selected index
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
get_color
(position)find_color_in_rect
(rect, color[, threshold])draw
(source, position, width, height)draw_on_image
(path, position, width, height)draw_color_on_image
(color, position, width, ...)Inherited from : py: class:AppearanceBase
__init__
([board])after_init
()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_image
()If dirty, the image will be reloaded.
add_images
(sources)Adds multiple images to background/costume.
add_image
(source)Adds an image to the appearance
set_image
(source)Sets the displayed image of costume/background to selected index
update
()Loads the next image, called 1/frame
__str__
()Return str(self).
register
(method)Register method for decorator.
Private Methods:
_update_all_costumes
()updates costumes for all tokens on board
_after_transformation_pipeline
()_blit_to_window_surface
()Blits background to window surface
Inherited from : py: class:AppearanceBase
_before_transformation_pipeline
()_after_transformation_pipeline
()
- add_image(source)[source]¶
Adds an image to the appearance
- Returns:
Index of the created image.
Examples
from miniworldmaker import * board = Board() token = Token() costume = token.add_costume("images/1.png") costume.add_image("images/2.png") board.run()
- Return type:
- property grid: Union[bool, tuple]¶
Shows a grid-overlay
grid can be True, False or a color-tuple
Examples
Show grid:
from miniworldmaker import * board = TiledBoard(4,4) board.tile_margin = 10 background = board.add_background("images/stone.png") background.is_textured = True token = Token() @token.register def on_key_down(self, key): self.move_right() background.grid = True board.run()
- parent¶
The parent of a Background is the associated board.