【问题标题】:Why am I getting this issue and how can I can resolve it?为什么我会遇到这个问题,我该如何解决?
【发布时间】:2018-01-05 20:01:22
【问题描述】:

我正在为我的 pygame 制作一个帮助屏幕,但每次运行它时都会收到此错误消息:

> self.surface.blit(self.helpscreen) TypeError: argument 1 must be
> pygame.Surface, not pygame.Rect

我不知道如何解决它,而且我还在学习 pygame,所以如果可能的话,我需要一个非常基本的答案。我的代码如下:

def help(self):

    pygame.init()
    self.FPS = 60
    self.fps_clock = pygame.time.Clock()
    self.surface = pygame.display.set_mode((640, 480))
    helpscreen = DISPLAY_SURF.fill(white)
    self.surface.blit(helpscreen)
    # This class sets the basic attributes for the window.
    # The clock is set to 60 and the name of the window
    # is set to The Hunt which is a working title for my project
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    while True:
        pygame.display.update()
        self.fps_clock.tick(self.FPS)
        self.process_game()

【问题讨论】:

  • 你的 helpscreen 是一个 rect 但 blit 需要一个 surface 对象
  • RTM: fill() 返回Rectblit() 需要 Surface
  • 我该如何解决?我需要更改代码的哪一部分以及如何更改?

标签: python pygame window blit


【解决方案1】:

要么只是填充显示表面self.surface.fill(white),要么创建一个背景表面并在self.surface 上进行blit:

helpscreen = pygame.Surface(self.surface.get_size())
helpscreen.fill(white)
self.surface.blit(helpscreen, (0, 0))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 2020-03-12
    • 2021-08-18
    • 2020-03-25
    • 2020-02-14
    相关资源
    最近更新 更多