2017-10-07 18 views
0

我想用Pygame在屏幕上提取圖片,但它不起作用;它給了我一個警告:在'image.py'中找不到引用'load'

在「image.py」

,並在執行時無法找到引用「負載」,它沒有給這樣的致命錯誤。我得到的只是一張沒有圖像的空白屏幕。我提到this和​​,但似乎並不奏效。這是我的代碼:

import pygame 

class Bouncer(object): 

    display_width = 600 
    display_height = 400 
    color_white = (255, 255, 255) 
    clock = pygame.time.Clock() 
    game_exit = False 
    bar_image = pygame.image.load('bar.png') # <------ here is the issue 

    def __init__(self): 

     pygame.init() 
     self.game_display = pygame.display.set_mode((self.display_width, 
     self.display_height)) 
     pygame.display.set_caption('Bouncy Bouncer') 


    def showBar(self): 

     self.game_display.blit(self.bar_image, (10, 10)) 


    def gameLoop(self): 

     while not self.game_exit: 

      for event in pygame.event.get(): 

       #on close quit 
       if event.type == pygame.QUIT: 

         self.game_exit = True 
         pygame.quit() 
         quit() 

       #on key press quit 
       if event.type == pygame.KEYDOWN: 

        if event.key == pygame.K_x: 

         self.game_exit = True 
         pygame.quit() 
         quit() 

      self.showBar() 

      self.game_display.fill(self.color_white) 
      pygame.display.update() 
      self.clock.tick(60) 


game_instance = Bouncer() 
game_instance.gameLoop() 

回答

0

我叫fiest叫我的形象再fill功能,因此它重疊的白色背景,因此,覆蓋圖像。所以,我所做的是先調用背景,然後調用圖像。