切换到 Pygame 全屏模式仅工作一次
我是 pygame.FULLSCREEN 模式的新手,我需要你的帮助。 我正在编写一个小游戏,其中玩家应该能够在正常模式和全屏模式之间切换。
当我运行程序时,窗口会打开,当我单击最大化按钮时,我会进入全屏模式。当我按退出键时,我回到正常模式。到目前为止一切正常。
但是,当我第二次单击最大化按钮时,窗口被最大化,但是,我没有进入全屏模式。此外,pygame 使用的窗口部分保持正常大小。
这是我的代码:
import pygame
pygame.init()
width = 500
height = 500
info = pygame.display.Info()
screen_width = info.current_w
screen_height = info.current_h
window = pygame.display.set_mode((width, height), pygame.RESIZABLE)
fullscreen = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
elif event.type == pygame.VIDEORESIZE:
window = pygame.display.set_mode((screen_width, screen_height), pygame.FULLSCREEN)
fullscreen = True
keys = pygame.key.get_pressed()
if keys[pygame.K_ESCAPE] and fullscreen:
window = pygame.display.set_mode((width, height), pygame.RESIZABLE)
fullscreen = False
window.fill((255, 255, 255))
pygame.display.update()
提前致谢!
I'm new to the pygame.FULLSCREEN mode, and I need your help.
I'm writing a small game, in which the player is supposed to be able to switch between normal mode and full screen mode.
When I run my program is that the window opens, and when I click on the maximize button I get into full screen mode. When I press escape, I get back to normal mode. Everything's working fine so far.
But when I click the maximize button a second time the window is maximized, however, I do not get into full screen mode. Also, the part of the window that pygame uses remains normal size.
Here's my code:
import pygame
pygame.init()
width = 500
height = 500
info = pygame.display.Info()
screen_width = info.current_w
screen_height = info.current_h
window = pygame.display.set_mode((width, height), pygame.RESIZABLE)
fullscreen = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
elif event.type == pygame.VIDEORESIZE:
window = pygame.display.set_mode((screen_width, screen_height), pygame.FULLSCREEN)
fullscreen = True
keys = pygame.key.get_pressed()
if keys[pygame.K_ESCAPE] and fullscreen:
window = pygame.display.set_mode((width, height), pygame.RESIZABLE)
fullscreen = False
window.fill((255, 255, 255))
pygame.display.update()
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每次调整窗口大小时都会执行 pygame.VIDEORESIZE 。因此,即使窗口更改为较小的尺寸,也会发生
pygame.VIDEORESIZE
。通过
event.set
获取窗口的新大小,并根据当前状态创建新的pygame.FULLSCREEN
或pygame.FULLSCREEN
显示全屏
。但可以通过按键设置全屏
,例如f。pygame.event.post()
一个新的pygame.event.Event ()
与正确的论点:The
pygame.VIDEORESIZE
is executed every time when the window is resized. Hence even if the window is changed to a smaller size, thenpygame.VIDEORESIZE
occurs.Get the new size of the window by
event.set
and create a newpygame.FULLSCREEN
orpygame.FULLSCREEN
display dependent on the current stateof
fullscreen
. But setfullscreen
by a key, for instance f.pygame.event.post()
a newpygame.event.Event()
with the proper arguments: