我正在尝试用pygame创建一个2d视频游戏
执行以下代码后:
from ship import Ship
from settings import Settings
import sys
import pygame
class Alien_invasion:
"""class to manage the game"""
def __init__(self):
"""initialise the game and create game ressources"""
pygame.init()
#print("ouzou")
self.settings=Settings()
self.screen = pygame.display.set_mode(self.settings.screen_height,self.settings.screen_width)
pygame.display.set_caption("Alien invasion")
self.ship = Ship(self)
def run_game(self):
"""start the game by calling a main loop"""
while True:
print("izann")
# wait keyboard or mouse event
for event in pygame.event:
if event.type == pygame.quit():
sys.exit()
# draw the screen after all the changes occured
self.screen.fill(self.settings.bg_color)
self.ship.blitme()
print("izan")
pygame.display.flip()
print("izan ssin")
if __name__ == "main":
partie = Alien_invasion()
partie.run_game()
我希望有一个pygame窗口,但控制台会打印:
pygame 2.0.1 (SDL 2.0.14, Python 3.9.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
之后什么也没发生
^{} 是一个函数,用于取消所有PyGame模块的初始化。当你这样做的时候
该函数被调用,所有PyGame模块都未初始化
^{} 对象的type属性指示事件的类型。您需要将事件类型与标识事件的枚举常量进行比较。退出事件由} 模块):
pygame.QUIT
标识(请参见^{因此,您必须与
pygame.QUIT
而不是pygame.quit()
竞争:此外,还有一个Indentation问题。必须在应用程序循环中绘制场景并更新显示,而不是在事件循环中:
带“####”的行是我的更正
相关问题 更多 >
编程相关推荐