PyGame 屏幕未填充和翻转

PyGame screen not filling and flipping

这是我游戏的class:

class App:
    def __init__(self):
        self._running = True
        self._display_surf = None
        self.clock = pygame.time.Clock()
        self.size = self.weight, self.height = 500, 640
        self.i = 0
    def on_init(self):
        pygame.init()
        self._display_surf = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
        self._running = True
 
    def on_event(self, event):
        if event.type == pygame.QUIT:
            self._running = False
    def on_loop(self):
        print(self.i)
        self.i += 1
    # here it should paint the screen green and then update the display
    def on_render(self):
        self._display_surf.fill(pygame.Color('green'))
        pygame.display.flip()
    
    def on_cleanup(self):
        pygame.quit()
 
    def on_execute(self):
        if self.on_init() == False:
            self._running = False
 
        while self._running:
            for event in pygame.event.get():
                self.on_event(event)
            self.on_loop()
            self.on_render()
            self.clock.tick(60)
        self.on_cleanup()
 
if __name__ == "__main__" :
    theApp = App()
    theApp.on_execute()

它应该打开一个带有绿色背景的 window,但它打开了一个没有背景的 window,只是带有深色主题的 MacO 上 window 的默认颜色。

这是 window

我尝试使用多种颜色来排除它绘制错误颜色的事实,我尝试调用更新而不是翻转,但没有任何效果。查看SO的其他问题,他们都说通过调用fill然后flip来做我已经做过的事情。

您(可能)使用的 pygame 版本与 pip3 install pygame 一起安装时当前附带的版本。

来自pygame的documentation

Mac installation

Recent versions of Mac OS X require pygame 2.

我遇到了同样的问题,运行 pip3 uninstall pygamepip3 install pygame==2.0.0.dev6 解决了它。