PyGame Loop

Window Title

We can set the window title by using set_caption()

    def init_display(self):
pygame.display.set_caption('PyGame Basics Workshop')
# Create surface disp_surf = pygame.Surface(self.size) return disp_surf.convert()

set_caption() sets the game caption (application title) on the top of the display.


Render

Let put something on screen during our game loop.

So let's add a render function.

Fill the surface with black:

# R G B BLACK = ( 0, 0, 0)
. . . def execute(self): # Event loop while self.running: self.check_events()
self.render() return def render(self): '''Render surface''' self.disp_surf.fill(BLACK) # Blit everything to screen self.display.blit(self.disp_surf, (0,0)) pygame.display.flip() return

blit(), stands for block transfer, will prepare image for 'transfer' onto the display surface. Or in other words, draw in buffer for transfer to surface.

flip(), will flip and update the whole display and show the changes to the game display.

update(), will only update a portion of the screen, that is the drawn rect or area without updating the whole display.

I would do a quick test and run the script now, to check that nothing is broken. There is nothing new to observe when the screen comes up, except that our screen is black instead of grey.