Pygame从全屏切换到正常不起作用 [英] Pygame switching from fullscreen to normal does not work
问题描述
我目前正在尝试设置从窗口模式和全屏模式切换.但是进入全屏并尝试返回后,游戏错误非常奇怪并粘在左上角
im currently trying to have a setting to switch from windowed mode and fullscreen. But after getting into fullscreen and trying to go back, the game bugs really weird and sticks to the topleft corner
顺便说一句:显示宽度 = 1280显示高度 = 720
Btw: display_width = 1280 display_height = 720
elif (Settings_Menu == True):
screen.fill((0,0,0))
screen.blit(settingsscreen, (0,0))
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if checkbox1.collidepoint(event.pos):
if(Fullscreen == False):
Fullscreen = True
screen = pygame.display.set_mode((display_width, display_height), pygame.FULLSCREEN)
else:
Fullscreen = False
screen = pygame.display.set_mode((display_width, display_height), pygame.RESIZABLE)
推荐答案
使用 pygame.display.toggle_fullscreen()
在全屏和窗口显示之间切换.
Use pygame.display.toggle_fullscreen()
to switch between fullscreen and windowed displays.
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if checkbox1.collidepoint(event.pos):
pygame.display.toggle_fullscreen()
文档文档 提到了显示驱动程序支持不是很好"使用 Pygame 1 时,但它应该适用于 Pygame 2 中的以下显示驱动程序:
The documentation documentation mentions that display driver support "is not great" when using Pygame 1, but it should work for the following display drivers in Pygame 2:
- 窗口 (Windows)
- x11 (Linux/Unix)
- wayland (Linux/Unix)
- 可可 (OSX/Mac)
但是,在撰写此答案时,Windows 的 toggle_fullscreen
中存在一个错误:
However, at the time of writing this answer, there is a bug in toggle_fullscreen
for Windows:
display.toggle_fullscreen 在将最大化窗口切换为全屏时不起作用 #2380
这篇关于Pygame从全屏切换到正常不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!