1

我想替换这个绘制矩形函数,而是让它产生一个图像。

矩形功能:

pygame.draw.rect(pygame.display.set_mode((800,600)), black, [0,0, 100, 100])

寻找这样的东西:

pygame.draw.image(**coordinatesX**, **coordinatesY**, **imagefile.jpg**)
4

2 回答 2

1

要加载图像,您需要存储文件,并使用以下方法加载它:

pygame.image.load('example.png')

现在您的代码应如下所示:

pygame.image.load('example.png')

pygame.display.set_mode((800, 600))
于 2020-04-07T23:26:14.933 回答
0

so first you have to load the image using image = pygame.image.load() and then use screen.blit(image) to draw it on the screen. For this to work you should define the screen at the beginning not in the draw function like you have done above. Just screen = pygame.display.set_mode((800,600)) should work.

于 2017-03-13T10:11:08.853 回答