繁体   English   中英

如何在Pygame中退出全屏模式?

[英]How can I exit Fullscreen mode in Pygame?

这可能是一个愚蠢的问题,但这是一个愚蠢的问题,我无法找到它的文档。

Pygame为display.set.mode()提供了这些标志:

pygame.FULLSCREEN    create a fullscreen display
pygame.DOUBLEBUF     recommended for HWSURFACE or OPENGL
pygame.HWSURFACE     hardware accelerated, only in FULLSCREEN
pygame.OPENGL        create an OpenGL renderable display
pygame.RESIZABLE     display window should be sizeable
pygame.NOFRAME       display window will have no border or controls

好的,我可以进入全屏模式..现在这是我的代码:

__author__ = 'EricsonWillians'

from pygame import *
import ctypes
init()
user32 = ctypes.windll.user32
screenSize = user32.GetSystemMetrics(0)/2, user32.GetSystemMetrics(1)/2

size = (screenSize)
screen = display.set_mode(size)
display.set_caption("Game")
done = False
clock = time.Clock()

def keyPressed(inputKey):
    keysPressed = key.get_pressed()
    if keysPressed[inputKey]:
        return True
    else:
        return False

while not done:
    for e in event.get():
        if e.type == QUIT:
            done = True
        if keyPressed(K_F10):
            if screen == display.set_mode(size):
                screen = display.set_mode(size, FULLSCREEN)
            else:
                screen = display.set_mode(size, "What flag should I put here for 'windowed'?")

    screen.fill((0,0,0))
    display.flip()
    clock.tick(60)

quit()

没有办法“切换回”全屏模式,因为SDL中没有“WINDOWED”标志。

并且“ pygame.display.toggle_fullscreen() ”不起作用。 (至少,我无法使它工作)。

我试过“-1”或“0”或“不是FULLSCREEN”,但它们都不起作用(标有“0”,屏幕变得“怪异”......我不知道会发生什么哈哈,但它不是窗口)型。

只是不要指定任何标志

if e.type is KEYDOWN and e.key == K_w:
    pygame.display.set_mode(size)
if e.type is KEYDOWN and e.key == K_f:
    pygame.display.set_mode(size, FULLSCREEN)

适合我。

编辑

要使用单个键切换,请使用:

if (e.type is KEYDOWN and e.key == K_f):
    if screen.get_flags() & FULLSCREEN:
        pygame.display.set_mode(size)
    else:
        pygame.display.set_mode(size, FULLSCREEN)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM