Drawing on the Screen
In this lesson, you’ll start drawing on the screen using a
Surface. Recall that a
Surface is a rectangular object on which you can draw, like a blank sheet of paper. The
screen object is a
Surface, and you can create your own
Surface objects separate from the display screen.
You’ll fill the screen with white, and add a new
Surface object to display on the screen. Add the code below your existing code, starting at line 44. Note the indentation, keeping the lines you are adding within the game loop, but outside the event loop:
44 # Fill the screen with white 45 screen.fill((255, 255, 255)) 46 47 # Create a surface and pass in a tuple containing its length and width 48 surf = pygame.Surface((50, 50)) 49 50 # Give the surface a color to separate it from the background 51 surf.fill((0, 0, 0)) 52 rect = surf.get_rect()
For more information about the
Rect classes, check out the following resources from the
Comments & Discussion
Become a Member to join the conversation.