我使用的是VisualDestAudio,但如果使用python IDLE运行,它会运行
import pygame, sys
def run_game():
pygame.init()
screen = pygame.display.set_mode((1200,800))
pygame.display.set_caption("Space Invasion")
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.display.flip()
run_game()
在进入循环之前,需要首先使用
pygame.init()
进行初始化。另外,我将sys.exit()
替换为pygame.quit()
,因为sys.exit()
会导致程序在试图关闭程序时不响应或者,您可以将循环放在的
run_game()
函数中,就像import random建议的那样相关问题 更多 >
编程相关推荐