2015-11-23 86 views
0

我有退出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() 

回答

0

可能不是正確的問題,但我敢肯定,你必須退出遊戲(在你的if event.type == QUIT:部分),像這樣:

if event.type == QUIT: 
    pygame.quit() 
    sys.exit() 

另外,如果你沒有import pygame.locals as *,那麼你可能需要使用pygame.locals.QUIT,而不是QUIT

+0

請參閱上面的註釋。它是python 3和python 2版本 –

+0

之間最大的區別之一嘿,很酷。不過,我相信你仍然需要調用'sys.exit()'。 另外,看看Sloth的答案。 – imyxh

+0

嗨,我已經解決了這個問題。其實,真的不需要它了。我知道我們必須在python 2中使用.exit(),但不再在Pygame的python 3版本中使用。只要設定完成不做,沒關係。這就像垃圾收集系統,你可以明確地退出它,但不是必需的。 –

0

這種情況通常發生在您致電pygame.quit()後,再致電pygame.display.flip()

您沒有顯示完整的代碼,但請確保在致電pygame.quit()後不要致電pygame.display.flip()

+0

實際上,根據文檔,我們不需要在python3版本中調用pygame.quit(),所以我不這樣做。我不知道問題在哪裏 –

相關問題