I am attempting to fade out some text on screen, using the set_alpha function with a new surface.
I am able to fade in the text, however when using this code:
label = myFont.render(textToFadeOut,1,(255,0,0))
newSurf = pygame.Surface(myFont.size(textToFadeOut))
for x in range (225):
newSurf.set_alpha(225 - x)
You are not clearing the frame before blitting the new surface. Try filling with the background color, then blitting your text again.
for x in range(225): screen.fill((0,0,0)) #or whatever your background color is newSurf.set_alpha(225-x) screen.blit(newSurf, (100,100)) pygame.display.flip() pygame.time.delay(20)
Think about it, it works with the fade in because the text is getting darker and darker, but it doesn't work with the fade out because you are blitting on top of your old text.