简体   繁体   English

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

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

It may be a silly question, but It's a silly problem that I can't find a doc for it. 这可能是一个愚蠢的问题,但这是一个愚蠢的问题,我无法找到它的文档。

Pygame gives me these flags for display.set.mode(): 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

Ok, I can enter the Fullscreen mode.. Now here's my code: 好的,我可以进入全屏模式..现在这是我的代码:

__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()

There's no way to "toggle back" the Fullscreen mode, because there's no "WINDOWED" flag as in SDL. 没有办法“切换回”全屏模式,因为SDL中没有“WINDOWED”标志。

And " pygame.display.toggle_fullscreen() " does not work. 并且“ pygame.display.toggle_fullscreen() ”不起作用。 (At least, I could not make it work). (至少,我无法使它工作)。

I've tried "-1" or "0" or "not FULLSCREEN", but none of them work (With "0" as a flag, the screen gets "weird".. I dont know what happens haha, but it's not WINDOWED). 我试过“-1”或“0”或“不是FULLSCREEN”,但它们都不起作用(标有“0”,屏幕变得“怪异”......我不知道会发生什么哈哈,但它不是窗口)型。

Just don't specify any flags 只是不要指定任何标志

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)

Works for me. 适合我。

EDIT 编辑

To toggle with a single key, use: 要使用单个键切换,请使用:

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