我正在编写一个pygame项目,我会告诉你......
import pygame
pygame.init()
WHITE = (255, 255, 255)
pad_width = 1024
pad_height = 512
def runGame():
global gamepad, clock
crashed = False
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
gamepad.fill(WHITE)
pygame.display.update()
clock.tick(60)
pygame.quit()
def initGame():
global gamepad, clock
pygame.init()
gamepad = pygame.display.set_mode((pad_width, pad_height))
pygame.display.set_caption('Pyflying')
clock = pygame.time.Clock()
runGame()
initGame()
这是代码,现在是错误......
Traceback (most recent call last):
File "C:/Users/dongjune/Desktop/PyCharm/scratch.py", line 36, in <module>
initGame()
File "C:/Users/dongjune/Desktop/PyCharm/scratch.py", line 33, in initGame
runGame()
File "C:/Users/dongjune/Desktop/PyCharm/scratch.py", line 14, in runGame
for event in pygame.event.get():
pygame.error: video system not initialized
我不知道如何编程....如果您知道错误,请回答!!! 而且,我是pygame的新手....ㅠ。ㅠ如果你知道如何使用pygame请告诉我!谢谢....
答案 0 :(得分:1)
你的缩进是错误的,解决这个问题:
def runGame():
global gamepad, clock
crashed = False
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
gamepad.fill(WHITE)
pygame.display.update()
clock.tick(60)
# pygame.quit() Remove this line, it shouldn't be in a loop or just break after it's executed