【问题标题】:Cannot find reference 'load' in 'image.py'在“image.py”中找不到参考“加载”
【发布时间】:2018-03-18 23:50:03
【问题描述】:

我想用 Pygame 将我的图像从屏幕上抹掉,但它不起作用;它给了我一个警告:

在“image.py”中找不到引用“load”

在执行期间,它没有给出这样的致命错误。我得到的只是一个没有图像的空白屏幕。我提到了thisthis,但似乎不起作用。这是我的代码:

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()

【问题讨论】:

    标签: python pygame


    【解决方案1】:

    我先调用了我的图像,然后调用了fill 函数,所以它与白色背景重叠,从而覆盖了图像。所以,我所做的就是先调用背景,然后调用图像。

    【讨论】:

      猜你喜欢
      • 2017-10-03
      • 2014-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-20
      • 1970-01-01
      相关资源
      最近更新 更多