【问题标题】:decisionBar() won't blit the image to the screen when it is called调用 decisionBar() 时,它不会将图像blit到屏幕上
【发布时间】:2020-06-11 12:21:28
【问题描述】:
    showScreen = True
    if showScreen == True:
        display = pygame.display.set_mode((500, 200))
        pygame.display.set_caption("Decision Bar Window")
        decisionBarImage = pygame.image.load('D:/Adriel/Documents/Python stuff/Games/Basic python game/Images/decision_bar.png')
        pygame.display.flip
        display.blit(decisionBarImage, (250,100))

在我的代码中,窗口会打开,但图像不会出现在上面。请帮忙。

【问题讨论】:

  • pygame.display.flip 什么都不做。你错过了括号:pygame.display.flip()

标签: python pygame blit


【解决方案1】:

在调用pygame.display.flip()之前,您必须将图像blit到屏幕表面。

然后你必须实际调用flip() 函数。在您的代码中,缺少 ()

另外,您需要一个事件循环,否则您的窗口将冻结或可能不显示任何内容。

所以你的代码应该是这样的:

    display = pygame.display.set_mode((500, 200))
    pygame.display.set_caption("Decision Bar Window")
    decisionBarImage = pygame.image.load('D:/Adriel/Documents/Python stuff/Games/Basic python game/Images/decision_bar.png')
    display.blit(decisionBarImage, (250,100))

    while True:
        for e in pygame.event.get():
            pass # TODO: handle at least the QUIT event     

        pygame.display.flip()

【讨论】:

  • 出现错误代码:无法打开 D:/Adriel/Documents/Python stuff/Games/Basic python game/Images/decision_bar.png
猜你喜欢
  • 1970-01-01
  • 2022-11-26
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 2010-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多