ninazzo
ninazzo

Reputation: 657

PyGame screen not filling and flipping

This is the class of my game:

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

It should open a window with a green background, but instead it opens a window without background, just the default color of a window on MacOs with the dark theme.

Here's the window enter image description here

I tried using multiple colors to exclude the fact it was painting the wrong color, I tried calling update instead of flip, nothing works. Looking on other question of SO, they all say to do what I've already done by calling fill and then flip.

Upvotes: 0

Views: 109

Answers (1)

Gerardo Zinno
Gerardo Zinno

Reputation: 1712

You are (probably) using the version of pygame that currently ships when installing it with pip3 install pygame.

From pygame's documentation :

Mac installation

Recent versions of Mac OS X require pygame 2.

I had the same problem and running pip3 uninstall pygame and pip3 install pygame==2.0.0.dev6 fixed it.

Upvotes: 1

Related Questions