求大神帮忙看下,为啥我退出全屏时,整个游戏画面缩在电脑屏幕左上角,还没有边框
import pygameimport sys
pygame.init()
size = (600, 600)
color = (230, 230, 230)
fullscreen = False
# 屏幕分辨率
screen = pygame.display.set_mode(size)
pygame.display.set_caption('打飞机')
image = pygame.image.load('images/ship.bmp')
rect = image.get_rect()
screen_rect = screen.get_rect()
print(screen_rect)
rect.midbottom = screen_rect.midbottom
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
sys.exit()
if event.key == pygame.K_F11:
fullscreen = not fullscreen
if fullscreen:
screen = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN | pygame.HWSURFACE)
else:
screen = pygame.display.set_mode(size)
screen.fill(color)
screen.blit(image, rect)
pygame.display.flip()
screen_rect = screen.get_rect()
rect.midbottom = screen_rect.midbottom
试试
import pygame
import sys
from pygame._sdl2.video import Window
pygame.init()
size = (600, 600)
color = (230, 230, 230)
fullscreen = False
# 屏幕分辨率
screen = pygame.display.set_mode(size)
pygame.display.set_caption('打飞机')
image = pygame.image.load('images/ship.bmp')
rect = image.get_rect()
screen_rect = screen.get_rect()
print(screen_rect)
rect.midbottom = screen_rect.midbottom
window = Window.from_display_module()
window_init_pos = window.position
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
sys.exit()
if event.key == pygame.K_F11:
fullscreen = not fullscreen
if fullscreen:
screen = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN | pygame.HWSURFACE)
else:
screen = pygame.display.set_mode(size)
window.position = window_init_pos
screen.fill(color)
screen.blit(image, rect)
pygame.display.flip()
screen_rect = screen.get_rect()
rect.midbottom = screen_rect.midbottom
参考 Pygame Display Position {:5_105:}
页:
[1]