【发布时间】:2018-03-18 23:50:03
【问题描述】:
我想用 Pygame 将我的图像从屏幕上抹掉,但它不起作用;它给了我一个警告:
在“image.py”中找不到引用“load”
在执行期间,它没有给出这样的致命错误。我得到的只是一个没有图像的空白屏幕。我提到了this 和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()
【问题讨论】: