Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a transparent image in pygame?

Consider a chess board, i have a transparent image of queen(queen.png) of size 70x70 and i want to display it over a black rectangle. Code:

BLACK=(0,0,0)
queen = pygame.image.load('queen.png')

pygame.draw.rect(DISPLAYSURF, BLACK, (10, 10, 70, 70))
DISPLAYSURF.blit(queen, (10, 10))

Error: i am not getting transparent image ie black rectangle is not visible at all, only queen with white background. Please suggest

like image 921
Saurabh Shrivastava Avatar asked Dec 19 '22 06:12

Saurabh Shrivastava


1 Answers

Try changing the line where you load in the queen to:

queen = pygame.image.load('queen.png').convert_alpha()
like image 171
Leafthecat Avatar answered Dec 22 '22 00:12

Leafthecat