brian.masse
brian.masse

Reputation: 31

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. It used to work, however when I updated to pygame 2.00, it no longer seems to work. 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!

Upvotes: 2

Views: 6258

Answers (2)

Kuba Beránek
Kuba Beránek

Reputation: 547

I think that this is a bug in PyGame 2.0.0, the same happens to me. It seems that the version of SDL that is distributed with PyGame has some issues.

Try to use the system installed SDL2, e.g. by using LD_PRELOAD:

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

You can read more about the issue here.

Upvotes: 0

luoabdellah
luoabdellah

Reputation: 21

Testing this on pygame 2.0.0.dev6, the code itself is working fine with no issues. 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. Setting different measurements is redundant unless you use pygame.SCALED.

You can find more information here.

Upvotes: 2

Related Questions