Overview
TheImages class displays unclickable images on the screen. It supports special image types like “Spinner” which creates a rotating animation effect.
Constructor
Parameters
The pygame surface to which the image will be drawn.
Path to the image file to load.
The position where the image will be drawn on the surface.
Special image behavior type. Use “Spinner” for rotating animation.
Methods
draw()
Draws the image to the surface. For Spinner type images, applies rotation animation.- Standard images: Simply blit the image to the surface
- Spinner images: Rotate the image 90 degrees at specific count intervals, completing a full rotation every ~30 frames (1 second at 30 FPS)
- Count 7: Rotate -90°, adjust Y position
- Count 15: Rotate -90°
- Count 22: Rotate -90°, adjust X position
- Count 30: Rotate -90°, reset count and positions
Attributes
img- The loaded pygame image surfaceimgtype- The type of image behaviorpos- Current position of the imagerect- The pygame.Rect defining the image boundariescount- Internal counter for animation timing (Spinner type)
Usage Examples
Static Image
Fromgame.py:
Spinner Animation
Fromgame.py:
Notes
- Images are loaded with
convert_alpha()for transparency support - The widget prints image dimensions to console during initialization
- Spinner rotation uses
pygame.transform.rotate()which may have quality issues on diagonals - Spinners complete a full 360° rotation approximately every second (at 30 FPS)
- Position adjustments in Spinner mode compensate for rotation artifacts