Pygame绘制错误

Arnyminer Z

我在使python应用程序正常工作时遇到了麻烦。

为了使我的工作更轻松,我开设了一些课程,您可以在此Github存储库中检查所有这些内容

我的主要课程是:

from UI import *

window = Window(Size(1000, 700), "WiSync", "logo.png")

button1 = Button(Size(50, 30), Position(10, 10), UIThemes.light)
window.add(button1)

window.start()

它不会给我任何错误,但是它不会画任何东西。我知道所有数据都可以,因为在我的抽屉类中我有一个print()电话:

def draw_rect(zone: Zone, color: Color, window: pygame.Surface):
    print("Drawing rect " + zone.to_string() + " with color " + color.to_string())
    pygame.draw.rect(window, color.get(), zone.get())

在我的应用程序循环中,有一个连续的消息:Drawing rect Zone(10, 10, 60, 40) with color flat_light_sea_blue,但屏幕上没有显示任何内容。

抱歉,如果我不够清楚,但是我是西班牙语,这很难解释。如果您还有其他疑问,请询问。

感谢您的帮助,您真棒;)

米歇尔·奥德威尔

问题是您没有pygame.display.update()在代码中的任何地方调用

您确实在绘制这些,Rect但是除非在主事件循环/主游戏循环中显示此行,否则它们不会在您的显示器上显示。

要解决此问题:

  • pygame.display.update()完成所有绘制后,只需在主循环的末尾添加一行即可

在你的回购协议,我看着UI.py__main_loop方法中,当然不需要Window任何行pygame.display.update()

这是固定代码:

def __main_loop(self):
        while self.running:
            # Draw all the elements
            for element in self.elements:
                element.draw()

            for event in pygame.event.get():
                if event.type is pygame.QUIT:
                    self.running = False

             pygame.display.update()

希望这个答案对您有所帮助,如果您还有其他疑问,请随时在下面发表评论!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章