如何在pygame中将png图片作为精灵上传而没有黑色背景?

xx_*_*_xx 3 python pygame python-3.x python-3.6 python-3.7

]如何让我的精灵显示在屏幕上。我已经有好几天了,但我无法让它出现在屏幕上,并且它要么一直占据屏幕,要么变成黑色。

导入pygame pygame.init()win = pygame.display.set_mode((600,600))

pygame.display.set_caption(“拿破仑”)

bg = pygame.image.load(“ apple.png”)。convert()win.blit(bg,[0,0])

flower = pygame.image.load(“ flower2.png”)。convert()win.blit(flower,[603,29])

pygame.display.update()

Hoo*_*oog 5

而不是convert()尝试convert_alpha()。假设您的图片具有Alpha通道(PNG应该不错),并且已将其应用于背景。如果您的图像没有Alpha通道,并且需要背景,则应调查该set_colorkey()功能。

另外,为了将来参考,您可以通过突出显示所有代码并按来格式化问题中的代码CTRL+K。使其更易于阅读(并且您将获得更快的答案!)