PyGame 多边形,使用一个元组作为参数

PyGame polygon, using a tuple as a parameter

我想在屏幕上画一个多边形,像这样:

coords = (653,333),(680,444),(680,444),(653,445)
pygame.draw.polygon(screen, (0, 0, 255), coords, 0)

然而,这并没有绘制到屏幕上。任何帮助表示赞赏。

答案:坐标应该是一个元组列表,所以对于我的示例,正​​确答案是:

coords = [(653,333), (680,444), (680,444), (653,445)]
pygame.draw.polygon(screen, (0, 0, 255), coords, 0)

您提供的代码似乎是正确的。我已经测试过了,它显示了一个三角形。正如评论中 skrx 所建议的,您的屏幕尺寸太小,您看不到它。

import pygame

pygame.init()
BLUE = (0,   0, 255)
size = [1920, 1080]
screen = pygame.display.set_mode(size)
done = False
clock = pygame.time.Clock()

while not done:
    clock.tick(10)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

    temp = (653, 333), (680, 444), (680, 444), (653, 445)
    pygame.draw.polygon(screen, BLUE, temp, 0)
    pygame.display.flip()

pygame.quit()