【问题标题】:How can I exit Fullscreen mode in Pygame?如何在 Pygame 中退出全屏模式?
【发布时间】:2014-03-25 16:20:22
【问题描述】:

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

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”或“非全屏”,但它们都不起作用(用“0”作为标志,屏幕变得“奇怪”..我不知道会发生什么哈哈,但它不是窗口)。

【问题讨论】:

    标签: python pygame toggle fullscreen exit


    【解决方案1】:

    只是不要指定任何标志

    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)
    

    【讨论】:

    • 你是对的!我以前尝试过,但使用相同的密钥。我和你一样做了,用另一个没有标志的钥匙,它起作用了。我想知道为什么它不能使用相同的键...
    猜你喜欢
    • 1970-01-01
    • 2014-12-15
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2017-11-16
    • 2014-03-07
    • 2023-03-19
    • 2012-03-29
    相关资源
    最近更新 更多