Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.

Using .blit() and .flip()

In this lesson, you’ll use .blit() and .flip() to get your newly created Surface to display on the screen. The term blit stands for Block Transfer, and .blit() is how you copy the contents of one Surface to another. You can only .blit() from one Surface to another, but since the screen is just another Surface, that’s not a problem.

Here’s how you draw surf on the screen:

54 # This line says "Draw surf onto the screen at the center"
55 screen.blit(surf, (SCREEN_WIDTH/2, SCREEN_HEIGHT/2))
56 pygame.display.flip()

The reason why the image looks off-center is that .blit() puts the top-left corner of surf at the location given. If you want surf to be centered, you would update the code like below:

54 # Put the center of surf at the center of the display
55 surf_center = (
56     (SCREEN_WIDTH-surf.get_width())/2,
57     (SCREEN_HEIGHT-surf.get_height())/2
58 )
59 
60 # Draw surf at the new coordinates
61 screen.blit(surf, surf_center)
62 pygame.display.flip()

For more information about the .blit() and .flip(), check out the following resources from the pygame documentation:

Comments & Discussion

John Berliner on March 23, 2020

Just curious why you introduced get_rect() here. I assume you’ll be using it later, e.g. to determine the coordinates of sprite on the screen, but unless I’m missing something, it’s not being used yet? Great tutorial BTW.

Become a Member to join the conversation.