鱼C论坛

 找回密码
 立即注册
查看: 1703|回复: 2

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

[复制链接]
发表于 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 | 显示全部楼层
试试


  1. import pygame
  2. import sys
  3. from pygame._sdl2.video import Window

  4. pygame.init()
  5. size = (600, 600)
  6. color = (230, 230, 230)
  7. fullscreen = False
  8. # 屏幕分辨率
  9. screen = pygame.display.set_mode(size)
  10. pygame.display.set_caption('打飞机')
  11. image = pygame.image.load('images/ship.bmp')
  12. rect = image.get_rect()
  13. screen_rect = screen.get_rect()
  14. print(screen_rect)
  15. rect.midbottom = screen_rect.midbottom
  16. window = Window.from_display_module()
  17. window_init_pos = window.position
  18. while True:
  19.     for event in pygame.event.get():
  20.         if event.type == pygame.QUIT:
  21.             sys.exit()
  22.         if event.type == pygame.KEYDOWN:
  23.             if event.key == pygame.K_q:
  24.                 sys.exit()
  25.             if event.key == pygame.K_F11:
  26.                 fullscreen = not fullscreen
  27.                 if fullscreen:
  28.                     screen = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN | pygame.HWSURFACE)
  29.                 else:
  30.                     screen = pygame.display.set_mode(size)
  31.                     window.position = window_init_pos

  32.     screen.fill(color)
  33.     screen.blit(image, rect)
  34.     pygame.display.flip()
  35.     screen_rect = screen.get_rect()
  36.     rect.midbottom = screen_rect.midbottom
复制代码


参考 Pygame Display Position
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-14 19:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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