I'm trying to make the background of my game fade to black over about 30 seconds. I'm doing so by trying to change the alpha value of my surface.
class Screen:
def __init__(self):
self.win = pygame.display.set_mode((1200, 800))
pygame.display.set_caption("Fire Game")
self.win.fill((255, 255, 255))
self.darkness = pygame.Surface((1200, 800))
self.darkness.fill((0, 0, 0))
self.darkness.set_alpha(0)
self.win.blit(self.darkness, (0, 0))
self.darknessLevel = 0
self.darknessCount = 0
pygame.display.flip()
def run(self):
self.darknessLevel = self.darknessCount / 10
# two ways of changing the alpha value
# 1. self.darkness.fill((0, 0, 0, self.darknessLevel), None, pygame.BLEND_RGBA_MULT)
# 2. self.darkness.set_alpha(self.darknessLevel)
self.win.blit(self.darkness, (0, 0))
pygame.display.flip()
self.darknessCount += 1
print(self.darkness.get_alpha())
print(self.darknessLevel)
the first option should work according to my research but does not, and whenever I use the print statement (self.darkness.get_alpha())I can see that the alpha value does not change. The second way does change the alpha value, however once the alpha value hits 1 it fades all of the ways to black. Experimenting around with this I hardcoded the set_alpha() and learned that the higher the number being the quicker it fades to black. I should also mention that Screen.run() is being called in my games main while loop.
example:
self.darkness.set_alpha(1) fades to black
self.darkness.set_alpha(10) fades to black but much quicker
any ideas on what I'm doing wrong or why this may be happening would be much appreciated