本文介绍了如何在pygame中绘制透明图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个国际象棋棋盘,我有一张女王/王后(queen.png)的透明图像,尺寸为70x70,我想在黑色矩形上显示它.代码:

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

推荐答案

尝试将皇后加载的行更改为:

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

queen = pygame.image.load('queen.png').convert_alpha()

这篇关于如何在pygame中绘制透明图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:31