Another problem you might run into (besides what the monkey said) is that you may need to use surface.convert() , which converts the image into a form in which alpha can be resized. You can do one of the following:
image = pygame.image.load("logo.png") image = image.convert()
or
image = pygame.image.load("logo.png").convert()
I found that although surface.convert_alpha() should do almost the same thing, it usually doesn't work. Try checking out this test code.
import pygame, sys pygame.init() window=pygame.display.set_mode((1500, 800)) background=pygame.Surface((window.get_rect().width, window.get_rect().height)) background.fill((0, 0, 0)) image=pygame.image.load('InsertImageHere.png') image=image.convert() image2=pygame.image.load('InsertImage2Here.png') image2=image2.convert_alpha() rect=image.get_rect() rect2=image2.get_rect() rect2.left=rect.width+1 i=1 while True: for event in pygame.event.get(): if event.type==12: pygame.quit() sys.exit() image.set_alpha(i) image2.set_alpha(i) window.fill((255, 255, 255)) window.blit(background, background.get_rect()) window.blit(image, rect) window.blit(image2, rect2) pygame.time.delay(20) i+=1 if i==255: i=1 pygame.display.update()
In my tests, image 1 disappeared properly, but image 2 remained dark all the time. You must try it for yourself; Your computer may work differently.
If surface.convert_alpha() works for you, you should use it, otherwise do what I said earlier. This should solve your problem.
It should also be noted that I used pygame.time.delay(20) , and not 2000, as before. 2000 will be too long if you increase alpha in the ranks of one.
source share