I have a part in my program that should display the currently playing song's name for the first 4 seconds, then fade out. Even though
Surface.get_alpha() returns expected results, the image still does not fade out.
Why is this? How can I make it work?
My code looks like this:
for event in settings.events: if pygame.mixer.music.get_pos() < 4000 and sounds.music.volume != 0: #This part creates the surface and determines the position show = 40 * 4 font = pygame.font.SysFont(typeface, 15) songname = font.render(sounds.music.playlist, True, settings.color) font_pos = songname.get_rect() font_pos.right = screenx - 10 font_pos.top = 10 alpha = 255 if event.type == USEREVENT + 1 and sounds.music.volume != 0: #The userevent is there to ensure it will fade out with the same speed #and not being related to fps #this decreases alpha show -= 1 if show > 0 else False if show < 40 * 4 and alpha > 0: alpha -= 1.6 songname.set_alpha(int(alpha)) if pygame.mixer.music.get_volume() != 0.0 and show != 0: #This does actually return the correct results print songname.get_alpha(), alpha screen.blit(songname, font_pos)