我正在学习如何使用 pygame,我只是想为我正在创建的游戏打开一个窗口.
程序编译得很好,我试着画一个圆圈,看看这是否会改变任何东西,但在这两种情况下,我仍然只是得到一个冻结的空白窗口.我的电脑有足够的存储空间,只打开了 2 个应用程序,但这是唯一一个卡住的应用程序.
导入pygamepygame.init()窗口 = pygame.display.set_mode((500, 500))我必须强制退出 Python,因为它停止响应.我有 Python 3.7.4 版和 Pygame 1.9.6 版.
有什么建议吗?
解决方案一个最小的、典型的 PyGame 应用程序
需要一个游戏循环
必须通过
导入pygamepygame.init()窗口 = pygame.display.set_mode((500, 500))# 主应用程序循环运行 = 真运行时:# 事件循环对于 pygame.event.get() 中的事件:如果 event.type == pygame.QUIT:运行 = 错误# 清除显示window.fill(0)# 绘制场景pygame.draw.circle(window, (255, 0, 0), (250, 250), 100)# 更新显示pygame.display.flip()I'm learning how to use pygame, and I'm just trying to open up a window for the game I'm creating.
The program compiles fine, and I tried drawing a circle to see if that would change anything but in both scenarios I still just get a blank window that freezes. My computer has plenty of storage space and only 2 applications open, and yet this is the only application that is freezing.
import pygame pygame.init() window = pygame.display.set_mode((500, 500))I have to force quit Python because it stops responding. I have Python version 3.7.4 and Pygame version 1.9.6.
Any advice?
解决方案A minimal, typical PyGame application
needs a game loop
has to handle the events, by either pygame.event.pump() or pygame.event.get().
has to update the Surface whuch represents the display respectively window, by either pygame.display.flip() or pygame.display.update().
See also Python Pygame Introduction
Simple example, which draws a red circle in the center of the window:
import pygame pygame.init() window = pygame.display.set_mode((500, 500)) # main application loop run = True while run: # event loop for event in pygame.event.get(): if event.type == pygame.QUIT: run = False # clear the display window.fill(0) # draw the scene pygame.draw.circle(window, (255, 0, 0), (250, 250), 100) # update the display pygame.display.flip()
更多推荐
Pygame 窗口在打开时冻结
发布评论