鱼C论坛

 找回密码
 立即注册
查看: 2075|回复: 3

求大神帮忙看下,为啥我退出全屏时,整个游戏画面缩在电脑屏幕左上角,还没有边框

[复制链接]
发表于 2021-9-3 16:43:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import pygame
import 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












想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-7 20:50:02 | 显示全部楼层
试试
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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-8 17:15:55 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2025-1-22 12:46:43 | 显示全部楼层
时隔三年多,我也遇到这种问题了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-2-24 01:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表