I've been trying to create a short code to use for a project that can fade in and from black, but for some reason only the function that fades in is working while the fade out function is being skipped more or less. By giving them parameters I confirmed that the problem is in the second function and that the transparency isn't changing at all. Here's my code-
import pygame
screen = pygame.display.set_mode((800,600))
image = pygame.image.load_extended('Map.png').convert_alpha()
image = pygame.transform.scale(image,(530,300))
image.set_alpha(0)
x = 0
y = 255
def fade_in(x):
while True:
screen.blit(image,(0,0))
pygame.display.update()
image.set_alpha(x)
pygame.time.delay(100)
if x < 255:
x += 5
else:
pygame.time.delay(500)
x = 0
fade_out(y)
def fade_out(y):
while True:
screen.blit(image,(0,0))
pygame.display.update()
image.set_alpha(y)
pygame.time.delay(100)
if y > 0:
y -= 5
else:
pygame.time.delay(500)
y = 255
fade_in(x)
while True:
fade_in(x)
Does anyone have an idea of what the problem might be?