So I wanted to make my menu fade in when the game starts and fade out when it quits. To do so, I created a second surface and planned to fill it with black and then gradually increase alpha. So in the constructor I added:
self.fadeInSurface = pygame.display.set_mode(screen_size, flag)
In the main game method before the game loop starts:
And the aforementioned
fadeIn() looks like this:
def fadeIn(self): for i in range(100): self.fadeInSurface.fill((0,0,0)) self.fadeInSurface.set_alpha(i) self.clock.tick(30) pygame.display.flip()
But instead of a fade-in, all I get is solid black screen for a short time and then the menu appears without any eye candy whatsoever. What am I doing wrong?
EDIT: Thanks to @Heckel, I made something like this:
def fadeIn(self): for i in range(255): self.surface.blit(self.background, (0,0), None, BLEND_RGB_MAX) self.surface.blit(self.curStart, (100,200), None) self.surface.blit(self.curQuit, (400,350), None) self.fadeInSurface.fill((0,0,0)) self.fadeInSurface.set_alpha(255-i) self.surface.blit(self.fadeInSurface, (0,0)) self.clock.tick(30) pygame.display.flip()
so that I have the main surface (called surface) on which I project my buttons and background and a secondary surface (called fadeInSurface) which is solid black but its alpha changes. Running this code, however, still results in solid black screen for a few seconds and then a sudden change to full clarity of the whole menu :( Why is that so?