I am making a game with the pygame module and now I got a problem. The program itself works fantastic, but the fullscreen mode which I wanted to enable does not work. I made a test program for fullscreen mode which works perfect, but when I tried to make the game fullscreen, the display does very strange. First the program starts. You can see it entering in fullscreen mode and displaying a text saying: "Loading..." Then the window disappears and reappears in it's original non-fullscreen size. the explorer bar on the bottom of the screen is displayed double and then the 2e explorer bar disappears. The game then runs in non-fullscreen mode. This is the program I use:
import pygame, sys, os
from pygame.locals import *
pygame.mixer.pre_init(44100, -16, 4, 2048)
pygame.init()
DISPLAYSURF = pygame.display.set_mode((476, 506), FULLSCREEN)
pygame.display.set_caption('Title of the game')
DISPLAYSURF.fill((128,128,128))
FONT = pygame.font.Font('freesansbold.ttf',20)
LoadingText = FONT.render('Loading...', True, (0,255,0))
LoadingRect = LoadingText.get_rect()
LoadingRect.center = (238,253)
DISPLAYSURF.blit(LoadingText, LoadingRect)
pygame.display.update()
# These files will be created when needed. They are now removed to prevent interference later.
try:
os.remove('LOAD.txt')
except IOError:
pass
try:
os.remove('OPEN.txt')
except IOError:
pass
try:
os.remove('RUN.txt')
except IOError:
pass
try:
os.remove('TEMP.txt')
except IOError:
pass
# All parts of the program are split into small programs that are callable with a main function
import ROIM
import ROIM_CreateNewGame
import ROIM_LevelMenu
import ROIM_Menu
import ROIM_SmallMenus
import ROIM_GameIntroduction
import SetupController
# RUN.txt is a file that says wich program to run
Run = 'Menu'
RUN = open('RUN.txt','w')
RUN.write('RUN\n')
RUN.write(Run)
RUN.close()
ChangeRun = False
FPS = 35
fpsClock = pygame.time.Clock()
while True: # MAIN GAME LOOP
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
Preferences = open('Preferences.txt')
PreferencesLines = Preferences.read().split('\n')
x = 1
Volume = -1
Brightness = -1
for Item in PreferencesLines:
if Item == 'BRIGHTNESS':
Brightness = int(PreferencesLines[x])
if Item == 'VOLUME':
Volume = int(PreferencesLines[x])
x += 1
Preferences.close()
assert Volume != -1
assert Brightness != -1
# The colors will be changed to the right brightness.
GREEN = (0,255 * (Brightness / 100),0)
YELLOW = (255 * (Brightness / 100),255 * (Brightness / 100),0)
RED = (255 * (Brightness / 100),0,0)
BLUE = (0,0,255 * (Brightness / 100))
WHITE = (255 * (Brightness / 100),255 * (Brightness / 100),255 * (Brightness / 100))
BLACK = (0,0,0)
GREY = (128 * (Brightness / 100),128 * (Brightness / 100),128 * (Brightness / 100))
# Every small program gets the main variables and constants as arguments
if Run == 'Menu':
ROIM_Menu.RunMenu(FONT, ChangeRun, GREEN, YELLOW, RED, BLUE, WHITE, BLACK, GREY, DISPLAYSURF, Volume, Brightness, fpsClock, FPS)
elif Run == 'NewGame':
ROIM_CreateNewGame.RunNewGame(FONT, ChangeRun, GREEN, YELLOW, RED, BLUE, WHITE, BLACK, GREY, DISPLAYSURF, Volume, Brightness, fpsClock, FPS)
elif Run == 'Game':
ROIM.RunGame(FONT, ChangeRun, GREEN, YELLOW, RED, BLUE, WHITE, BLACK, GREY, DISPLAYSURF, Volume, Brightness, fpsClock, FPS)
elif Run == 'SmallMenu':
ROIM_SmallMenus.RunSmallMenu(FONT, ChangeRun, GREEN, YELLOW, RED, BLUE, WHITE, BLACK, GREY, DISPLAYSURF, Volume, Brightness, fpsClock, FPS)
elif Run == 'LevelMenu':
ROIM_LevelMenu.RunLevelMenu(FONT, ChangeRun, GREEN, YELLOW, RED, BLUE, WHITE, BLACK, GREY, DISPLAYSURF, Volume, Brightness, fpsClock, FPS)
elif Run == 'Introduction':
ROIM_GameIntroduction.RunIntro(FONT, ChangeRun, GREEN, YELLOW, RED, BLUE, WHITE, BLACK, GREY, DISPLAYSURF, Volume, Brightness, fpsClock, FPS)
elif Run == 'Setup':
SetupController.Run_Controller_Setup(FONT, ChangeRun, GREEN, YELLOW, RED, BLUE, WHITE, BLACK, GREY, DISPLAYSURF, Volume, Brightness, fpsClock, FPS)
else:
assert False
# Every program edits the RUN file before finishing
ChangeRun = False
RUN = open('RUN.txt')
assert RUN.readline() == 'RUN\n'
Run = RUN.readline().split('\n')[0]
RUN.close()
The game runs fine, but not in fullscreen mode.
DISPLAYSURF is not edited in the programs. Which means that I do not call pygame.display.set_mode()
.
I use windows 8 and python 3.4 .
Is it because I pass the window object as an argument?
I have no clue of what I did wrong.
I found that the problem was the subprograms. In every imported program you have to import pygame, but I thought that I also had to init pygame again, but that is not necessary. I removed pygame.init()
in each subprogram and it works perfect now.
You might need some additional flags passed in to the display surface's .set_mode() function. The following works for me on Windows 7:
DISPLAYSURF = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), FULLSCREEN | HWSURFACE | DOUBLEBUF)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With