Python 为什么pygame显示黑色窗口?
进口 展示Python 为什么pygame显示黑色窗口?,python,python-3.x,pygame,Python,Python 3.x,Pygame,进口 展示 #Imports import pygame, sys, time, random from pygame.locals import * 事件循环 pygame.init() #initializes pygame window pygame.display.set_caption('Parkour') #titlebar caption Bg=pygame.display.set_mode((800,600),0,32) #sets main surface """----
#Imports
import pygame, sys, time, random
from pygame.locals import *
事件循环
pygame.init() #initializes pygame window
pygame.display.set_caption('Parkour') #titlebar caption
Bg=pygame.display.set_mode((800,600),0,32) #sets main surface
"""--------------------------------------------------------------------------"""
背景(问题)是的,我是一个初学者,但这不应该填满屏幕然后更新吗?Bg是真的,所以它应该持续运行,对吗
gameActive = True
while gameActive:
#print (event)
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameActive = False
pygame.quit()
quit()
此外,变量
Bg
是与窗口关联的:
Bg=pygame.display.set_模式((800600),0,32)#设置主界面
对于布尔状态,不要使用相同的变量名:
Bg=True
我建议更改显示表面的名称(例如屏幕),因为您在屏幕中使用了此名称。填充((0,0255))
:
screen=pygame.display.set_模式((800600),0,32)#设置主界面
当然,您必须填充背景并更新主应用程序循环中的显示。主要应用程序必须
- 处理事件
- 清除显示器
- 画场景
- 更新显示
#导入
导入pygame、sys、time、random
从pygame.locals导入*
pygame.init()初始化pygame窗口
pygame.display.set_标题(“跑酷”)标题栏标题
screen=pygame.display.set_模式((800600),0,32)#设置主界面
#主应用程序循环
gameActive=True
当游戏处于活动状态时:
#处理事件循环中的事件
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
gameActive=False
#清除显示器
屏幕填充((0,0255))
#画场景
#[…]在这里画东西
#更新显示
pygame.display.flip()
请将您的所有代码片段放在一起,以便其他人运行。
#Background
Bg = True
while Bg:
screen.fill((0,0,255))
pygame.display.flip()