I mean, in Python. The transparency. I simply want to an image appear and slowly vanish, aka, get transparent.
My actual code.
def post_texto_1():
inicio = True
alpha = 255
screen.fill((0, 0, 0))
while inicio:
for event in pygame.event.get():
if event.type == QUIT:
exit()
imagen_postTexto1.set_alpha(alpha)
screen.blit(imagen_postTexto1, (0, 0))
alpha -= 1
if alpha == 0:
inicio = False
tex2 = u"¿Dónde estoy? ¿A dónde voy?"
mostrar_mensaje(tex2, (255, 255, 255))
print("El alpha de la imagen es : "+str(alpha))
pygame.display.update()
When you use convert_alpha()
, you change the pixel format of an image including per pixel alphas.
According to the PyGame documentation for set_alpha()
, the alpha value will be ignored, if the Surface format (i.e. the image) contains per pixel alphas.
If you still need to display a transparent image and want to use set_alpha()
, you could use PyGames set_colorkey()
method to set one color transparent.
Use the following function to vanish an image:
def vanish_image(image, screen, background_color):
image = pygame.image.load(image).convert()
image.set_colorkey((0,0,0)) #RGB-value for transparent color if needed
alpha = 255
while True:
if alpha < 0: #exit function if alpha is smaller than 0
return
alpha -= 1
screen.fill(background_color) #"clear" last blitted image
image.set_alpha(alpha)
pygame.display.update(screen.blit(image,(0,0))) #blit new image onto surface and update only this area
pygame.time.delay(20) #wait 20 milliseconds
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments