Before, I wanted to find an example that could achieve fade in and fade out, but I couldn't find it after searching for a long time, basically it couldn't achieve fade out. Also, I saw someone say that set_alpha() is useless, which I will talk about later.
Below is the code example.
for a in range(26):
clock.tick(FPS)
screen.fill((0,0,0))
if xianshi_yincang==1:
picture.set_alpha(a*10)
else:
picture.set_alpha(255-a*10)
screen.blit(picture,(weight/2-450,130),(0,0,900,485))
pygame.display.flip()
First of all, set_alpha() can be used, but the transparency needs a foil to show the effect. So, it is important to constantly fill the screen with the background color. I tried it before, without a picture below or without filling the background color, set_alpha() has no effect.
The xianshi_yincang variable controls fade in and out, 1 is fade in, 2 is fade out.