【发布时间】:2014-07-05 06:45:21
【问题描述】:
我正在使用 pygame 模块制作游戏,但现在遇到了问题。该程序本身运行良好,但我想启用的全屏模式不起作用。我为全屏模式制作了一个测试程序,效果很好,但是当我尝试让游戏全屏时,显示效果很奇怪。 首先程序启动。 您可以看到它以全屏模式进入并显示一条文字:“正在加载...” 然后窗口消失并以原始的非全屏尺寸重新出现。 屏幕底部的资源管理器栏显示双倍,然后 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 。
是因为我将窗口对象作为参数传递吗?
我不知道我做错了什么。
【问题讨论】:
-
好的,至少据我所知,pygame 全屏目前无法在 Windows 中运行。你可能想在 Windows 上搜索全屏 pygame 或类似的东西。
标签: python pygame fullscreen