我正在使用 pygame 1.9.6 创建游戏。但是,正如您通过运行这个简单的示例所看到的,即使带有
FULLSCREEN
标志,窗口周围也会出现一些黑色边框。
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((900, 500), FULLSCREEN)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
screen.fill((255, 255, 255))
pygame.display.flip()
我尝试在屏幕初始化中添加标志
NOFRAME
,但没有成功。
我想知道是否可以删除边框,例如通过增加屏幕尺寸以适合当前屏幕。但我也想保留
900x500
的决议。
pygame
可以调整整个屏幕的大小吗?我是否必须 blit()
Surface
上的所有内容,然后重新缩放并将其绘制在实际屏幕上?
消除黑条的唯一方法是将
pygame.display.set_mode((width, height))
设置为用户分辨率。使用 pygame.display.Info()
获取用户的显示分辨率。此外,您可以拥有首选分辨率,例如 900 x 500
以获得“差异数”以获得复古/像素化外观。
resolution = pygame.display.Info()
width = resolution.current_w
height = resolution.current_h
dx = width // 900
dy = height // 500
这个 dx 和 dy 然后可以用来将所有内容缩放到更大的尺寸。
我会尝试这个代码:
import pygame
from pygame.locals import *
pygame.init() # You forgot the initialize the pygame window!
resolution = pygame.display.Info() # Get the users resolution
width = resolution.current_w
height = resolution.current_h
screen = pygame.display.set_mode((width, height), FULLSCREEN, 0, 32)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
screen.fill((255, 255, 255))
mouse_pos = pygame.mouse.get_pos()
pygame.draw.circle(screen, (0, 0, 255), mouse_pos, 20)
pygame.draw.circle(screen, (0, 0, 200), mouse_pos, 18)
pygame.draw.circle(screen, (0, 0, 100), mouse_pos, 15)
pygame.draw.circle(screen, (0, 0, 50), mouse_pos, 10)
pygame.display.flip()
谢谢
@Glenn Mackintosh
!
删除黑色边框的最佳方法实际上是在屏幕声明中添加
SCALED
标志,如下所示:
screen = pygame.display.set_mode((900, 500), FULLSCREEN|SCALED)
但是要使用它,需要pygame版本
2.0.0
或更高版本。
现在这个问题似乎在更新的 pygame 版本中得到了解决,游戏窗口现在已调整大小以默认最大化已用空间。