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.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

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

shevachp on April 22, 2020

Hi Chris, Am really enjoying this tutorial. I was just wondering is there any reason to make the black rectangle another surface instead of just pygame.draw.rectangle(....)?

Jon Fincher RP Team on April 22, 2020

shevachp, you will be using the rect in a later step to draw an image on the screen. This step prepares for the next.

Become a Member to join the conversation.