我有退出pygame的視頻系統未初始化pygame的
當我試圖關閉窗口中的一些問題,它告訴我視頻系統沒有初始化 我不知道怎麼收拾的圖像在這裏,對不起。錯誤發生在標線「!!!!!」
這裏是我的代碼
# PreTitleScreen
# cited from http://programarcadegames.com/python_examples/
# f.php?file=sprite_collect_blocks.py
# the framework of this file are mostly cited from the above address
import pygame, configure, instructions, game
# constant
PTS_WIDTH = 1024 # pre screen width
PTS_HEIGHT = 768 # pre Screen height
class TitleScreen():
def __init__(self):
self.c = configure.Configure()
done = False
pygame.init()
clock = pygame.time.Clock()
while not done:
self.screen = pygame.display.set_mode([PTS_WIDTH,PTS_HEIGHT])
pygame.display.set_caption("Bomberman")
# import background image
bgImagePath = self.c.IMAGE_PATH + "titleScreen.png"
bgImage = pygame.image.load(bgImagePath).convert()
bgImage = pygame.transform.scale(bgImage,(PTS_WIDTH,PTS_HEIGHT))
self.screen.blit(bgImage,[0,0])
pygame.mixer.music.load(self.c.AUDIO_PATH + "title.mid")
pygame.mixer.music.play()
# pygame.display.flip()
notValidOp = False
# under valid control mode
while not notValidOp:
print("enter the inner loop")
# get mouse position
pos = pygame.mouse.get_pos()
# testCode
for event in pygame.event.get():
# deal with the exit
print('event.type', event.type)
if event.type == pygame.QUIT:
print("quit")
notValidOp = not notValidOp
done = not done
elif event.type == pygame.MOUSEBUTTONDOWN:
print("get from general",pos)
if self.inBoundary(pos[0],pos[1],25, 500, 250, 550):
self.playGame("S")
elif self.inBoundary(pos[0],pos[1],25, 550, 250, 600):
self.playGame("M")
elif self.inBoundary(pos[0],pos[1],25, 600, 250, 650):
self.instructions()
elif self.inBoundary(pos[0],pos[1],25, 650, 250, 700):
print("high Score")
print("get from score",pos)
elif self.inBoundary(pos[0],pos[1],40, 700, 250, 750):
print("exit")
done = not done
notValidOp = not notValidOp
# Go ahead and update the screen with what we've drawn.
pygame.display.flip() # !!!!!!!!!!!!!!
# Limit to 60 frames per second
clock.tick(self.c.FPS)
def inBoundary(self,x0,y0,x1,y1,x2,y2):
if ((x1 <= x0 <= x2) and (y1 <= y0 <= y2)):
return True
return False
def instructions(self):
instructions.Instructions()
def playGame(self,mode):
game.Game(mode)
# pygame.init()
# test Code below
TitleScreen()
請參閱上面的註釋。它是python 3和python 2版本 –
之間最大的區別之一嘿,很酷。不過,我相信你仍然需要調用'sys.exit()'。 另外,看看Sloth的答案。 – imyxh
嗨,我已經解決了這個問題。其實,真的不需要它了。我知道我們必須在python 2中使用.exit(),但不再在Pygame的python 3版本中使用。只要設定完成不做,沒關係。這就像垃圾收集系統,你可以明確地退出它,但不是必需的。 –