I made a program in Python with a flashlight and want to make the battery meter change when the flashlight is on. I made a simpler version where it only changes like this:
high = pygame.image.load("battery_high.jpeg")
medium = pygame.image.load("battery_med.jpeg")
low = pygame.image.load("battery_low.jpeg")
battery = 100
while True:
battery -= 0.1;
for event in pygame.event.get():
if event.type == pygame.QUIT:
break
game_display.fill(WHITE)
battery_img = None
if battery > 66:
battery_img = high;
elif battery > 33:
battery_img = medium;
else:
battery_img = low;
display.blit(battery_img, (0, 0));
pygame.display.flip()
The battery change isn't that smooth, if I have 60% battery I want the meter to be 60% full. How do I do this? I think the fix is to cut off the image, but I don't know how.
You only have 3 images. Either you need more images or you have to draw the scale in Pygame. Here is a piece of simple code that draws a dynamic scale on an image. The scale is just a rectangle that changes in height depending on the battery charge: