本文介绍了删除pygame全屏中的黑色边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个启用了 pygamefullscreen 的游戏(示例如下):

I create a game with pygame and fullscreen enabled (example below):

import pygame
from pygame.locals import *

screen = pygame.display.set_mode((900, 500), 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()

丑陋的黑色边框破坏了渲染.

An ugly black border ruins the rendering.

我尝试在屏幕初始化中添加标志 NOFRAME,但没有成功.

I try to add the flag NOFRAME in the screen initialisation, but it didn't work.

我认为可以通过调整屏幕大小来移除边框.但我想保持 900x500 分辨率.pygame 可以调整整个屏幕的大小吗?但它很慢吗?我目前正在创建的游戏几乎使用了所有的计算机能力.

I think it is possible to remove the border with resizing the screen. But I want to keep the 900x500 resolution. Can pygame resize the entire screen? But is it slow? The game I'm currently creating uses almost all the computer power.

推荐答案

感谢@Glenn Mackintosh!

Thanks @Glenn Mackintosh!

去除黑色边框的最好方法实际上是在屏幕声明中添加 SCALED 标志,如下所示:

The best way to remove the black border is actually to add the SCALED flag in the screen declaration like this:

screen = pygame.display.set_mode((900, 500), FULLSCREEN|SCALED)

但要使用它,需要 pygame 版本 2.0.0 或更高版本.

But to use it, the pygame version 2.0.0 or more is required.

这篇关于删除pygame全屏中的黑色边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:06