我有此代码:
import sys
import pygame
pygame.init()
size = 320, 240
black = 0, 0, 0
red = 255, 0, 0
screen = pygame.display.set_mode(size)
screen.fill(black)
pygame.draw.rect(screen, red, (10,10,50,50))
pygame.display.flip()
但实际上并没有在PyGame窗口中创建矩形。
答案 0 :(得分:2)
如何绘制矩形是正确的。您只需要在while循环中不断调用pygame.display.flip()
即可呈现游戏。
import pygame
pygame.init()
size = 320, 240
black = 0, 0, 0
red = 255, 0, 0
screen = pygame.display.set_mode(size)
screen.fill(black)
pygame.draw.rect(screen, red, (10,10,50,50))
done = False
while not done:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True
pygame.display.flip()
pygame.quit()