简体   繁体   English

如何全屏pygame

[英]How to Fullscreen pygame

I have a game that needs to be set in fullscreen.我有一个需要全屏设置的游戏。 I am using the standard pygame.FULLSCREEN, when initializing the screen.我在初始化屏幕时使用标准的 pygame.FULLSCREEN。 It used to work, however when I updated to pygame 2.00, it no longer seems to work.它曾经可以工作,但是当我更新到 pygame 2.00 时,它似乎不再工作。 I am using the code below, and before I get any information or the screen finished setting up it produces the error code:我正在使用下面的代码,在我得到任何信息或屏幕完成设置之前,它会产生错误代码:

pygame.error: Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface

The code I am running is:我正在运行的代码是:

import pygame

pygame.init()

controller = pygame.joystick.Joystick(0)
controller.init()

width = 600
height = 600 

screen = pygame.display.set_mode((width, height), pygame.FULLSCREEN)
pygame.display.init()


pygame.display.flip()
screen.fill((77,214,255))

running = True
while running:
    for event in pygame.event.get():

        if event.type == pygame.QUIT:
            pygame.quit()
            running = False

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                pygame.quit()
                running = False

If anybody knows of a solution to this problem, that would be greatly appreciated!如果有人知道这个问题的解决方案,那将不胜感激!

Testing this on pygame 2.0.0.dev6, the code itself is working fine with no issues.在 pygame 2.0.0.dev6 上对此进行测试,代码本身运行良好,没有任何问题。 However as others mentioned, it is better to set the width and height to 0 if you want the game to only open in full screen.但是正如其他人提到的,如果您希望游戏仅以全屏模式打开,最好将宽度和高度设置为 0。 Setting different measurements is redundant unless you use pygame.SCALED.除非您使用 pygame.SCALED,否则设置不同的度量是多余的。

You can find more information here .您可以在此处找到更多信息。

I think that this is a bug in PyGame 2.0.0, the same happens to me.我认为这是 PyGame 2.0.0 中的一个错误,同样的情况也发生在我身上。 It seems that the version of SDL that is distributed with PyGame has some issues.似乎与 PyGame 一起分发的 SDL 版本存在一些问题。

Try to use the system installed SDL2, eg by using LD_PRELOAD:尝试使用系统安装的 SDL2,例如通过使用 LD_PRELOAD:

$ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libSDL2.so python app.py

You can read more about the issue here .您可以在此处阅读有关该问题的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM