我正在使用pygame模块进行游戏,现在我遇到了问题。该程序本身很棒,但我想启用的全屏模式不起作用。我为全屏模式制作了一个完美的测试程序,但是当我试图让游戏全屏时,显示效果非常奇怪。 首先程序启动。 您可以看到它以全屏模式进入并显示一条文字:"正在加载......" 然后窗口消失并重新出现在其原始的非全屏尺寸中。 屏幕底部的资源管理器栏显示为double,然后2e资源管理器栏消失。 然后游戏以非全屏模式运行。 这是我使用的程序:
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()
游戏运行正常,但不是全屏模式。
DISPLAYSURF未在程序中编辑。这意味着我不打电话给pygame.display.set_mode()
。
我使用Windows 8和python 3.4。
是因为我将窗口对象作为参数传递?
我不清楚我做错了什么。
答案 0 :(得分:2)
您可能需要将一些额外的标记传递到显示表面的.set_mode()函数。以下适用于Windows 7:
DISPLAYSURF = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), FULLSCREEN | HWSURFACE | DOUBLEBUF)
答案 1 :(得分:1)
我发现问题是子程序。在每个导入的程序中你必须导入pygame,但我认为我还必须再次初始化pygame,但这不是必需的。我在每个子程序中删除了pygame.init()
,现在它完美无缺。