进入全屏模式时,窗口进入全屏模式,但颜色不进入全屏模式。我尝试检查它是否处于全屏状态并使用RESIZE属性刷新,但这仅适用于在全屏之外调整大小的情况。码:

import time
import ctypes, pygame
from Game import Character
from pygame.locals import (
    K_UP,
    K_DOWN,
    K_LEFT,
    K_RIGHT,
    K_ESCAPE,
    K_F11,
    KEYDOWN,
    QUIT
)
print("Starting")

global active
global screen

user32 = ctypes.windll.user32
SCREEN_WIDTH = int(round(user32.GetSystemMetrics(0) / 2, 0))
SCREEN_HEIGHT = int(round(user32.GetSystemMetrics(1) / 2, 0))

timeOne = time.time()

pygame.init()

def Main():
    active = True
    screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.RESIZABLE)
    pygame.display.set_caption("Test")

    print("Done. Complete in ", round(time.time()-timeOne, 2), "seconds.")

    while active:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                active = False
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    active = False
                elif event.key == K_F11:
                    if screen.get_flags() & pygame.FULLSCREEN:
                        pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
                    else:
                        pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.FULLSCREEN)
            elif event.type == pygame.VIDEORESIZE:
                screenSize = event.size
                screen = pygame.display.set_mode(screenSize, pygame.RESIZABLE)

        screen.fill((0, 0, 255))
        pygame.display.flip()

    pygame.quit()

Main()


这是我第一次参加pygame,因此对于任何菜鸟错误,请提前道歉。

最佳答案

当显示切换到全屏窗口时,我正在使用的代码确定屏幕尺寸。我不认为VIDEORESIZE事件会在开关中触发,因为视频大小实际上并没有更改(也许有一种方法可以触发该事件,但是我认为不同的全屏Vs窗口大小是历史遗迹) 。

这样做的结果是在切换期间必须重新初始化显示。下面的程序将在F11上的全屏窗口模式下切换,从而将整个屏幕涂成蓝色。在Internet上有一些较旧的代码片段和有关此切换技术的注释,其中包括鼠标操作的更改等。我发现这些不再是必需的……至少在我的测试系统上。 (请告诉我们是否需要进一步的处理。)

import pygame

# Window size
WINDOW_WIDTH      = 1600
WINDOW_HEIGHT     = 900
WINDOW_FULLSCREEN = False

SKY_BLUE = ( 61,  55, 254)

### Initialisation
pygame.init()
SURFACE = pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE
window  = pygame.display.set_mode( ( WINDOW_WIDTH, WINDOW_HEIGHT ), SURFACE )
pygame.display.set_caption("Full Screen Test")


clock = pygame.time.Clock()
done = False
while not done:

    # Handle user-input
    for event in pygame.event.get():
        if ( event.type == pygame.QUIT ):
            done = True
        elif ( event.type == pygame.VIDEORESIZE ):
            WINDOW_WIDTH  = event.w
            WINDOW_HEIGHT = event.h
            window  = pygame.display.set_mode( ( WINDOW_WIDTH, WINDOW_HEIGHT ), SURFACE )

    # Movement keys
    keys = pygame.key.get_pressed()
    if ( keys[pygame.K_q] and ( keys[pygame.K_RCTRL] or keys[pygame.K_LCTRL] ) ):
        print("^Q")
        done = True
    elif ( keys[pygame.K_F11] ):
        print("fullscreen toggle")
        pygame.display.toggle_fullscreen()
        new_screen  = pygame.display.get_surface()
        bits        = new_screen.get_bitsize()
        screen_info = pygame.display.Info()
        new_width   = screen_info.current_w
        new_height  = screen_info.current_h
        print("new_width=%d, new_height=%d" % (new_width, new_height) )
        if ( window.get_flags() & pygame.FULLSCREEN ):
            flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
        else:
            flags = pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE
        pygame.display.quit()
        pygame.display.init()
        window        = pygame.display.set_mode( ( new_width, new_height ), flags, bits )
        WINDOW_WIDTH  = new_width
        WINDOW_HEIGHT = new_height
        #pygame.key.set_mods( 0 ) #HACK: work-a-round for a SDL bug??

    # Update the window, but not more than 60fps
    window.fill( SKY_BLUE )
    pygame.display.flip()

    # Clamp FPS
    clock.tick_busy_loop(60)

    # Failsafe - exit after 15 seconds (in case your display goes sqrilly)
    if ( pygame.time.get_ticks() > 15000 ):
        print("Exiting Failsafe")
        break

pygame.quit()

关于python - 进入全屏模式时,屏幕尺寸未更新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59380953/

10-14 19:01