Image¶
The Image component displays images on the screen with customizable appearance.
Basic Usage¶
# Create an image element
image = pygameui.Image(
position=(100, 100),
src="path/to/image.png",
centered=True # Center the image at the position
)
# In the main loop
image.update(events) # events parameter for API consistency
image.draw(screen)
Properties¶
position: tuple[int, int],
src: str,
width: int = 0,
height: int = 0,
scale: int = 1,
centered: bool = False
position: Tuple of (x, y) coordinates for placing the imagesrc: Path to the image file (relative or absolute)width: Width to resize the image to in pixels, 0 indicates using original width (modified by scale)height: Height to resize the image to in pixels, 0 indicates using original height (modified by scale)scale: Factor to scale the image by compared to the original size (1 = original size, 2 = double size), only applies when width and height are not setcentered: If True, the image is centered on the provided position; otherwise, the top-left corner is at the position
Methods¶
All methods inherited from the Element class.
Update Method¶
update: Updates the image element's state including animations. Theeventsparameter is included for API consistency with other components but is not used by the Image class.
Setters¶
set_image: Change the displayed image to a new image filescale: Change the scale factor of the image relative to its original size
Getters¶
get_image: Get the current pygame Surface containing the imageget_scale: Get the current scale factor applied to the image