Surface and Screen
The most important part of pygame is surface. We can regard the surface as a blank piece of white paper. You can perform many operations on the surface, such as drawing lines on the surface, filling some areas on the surface with a certain color, and copying images to the surface, copy, set, or read the color of a point on the surface. A surface can be of any size, and a game can have any number of surfaces. A special surface is the display surface created using pygame. display. set_mode. It represents the screen, and any operations on it will appear on the user's screen. A game can only have one such surface, which is the limitation of SDL.
How to Create a surface? As mentioned earlier, you can use pygame. display. set_mode () to create a special display surface. In addition, you can use image. Load () to create a surface containing images, and use font. Render () to create a surface containing text. You can even use surface () to create a surface that does not contain anything.
Most methods of surface are not important. You only need to learn bits (), fill (), set_at (), and get_at.
The initialization operation of the display surface is as follows:
screen = pygame.display.set_mode((1024, 768))
Or screen = pygame. display. set_mode (1024,768), pygame. fullscreen)
You can use set_mode to change the game in the original window to full screen. Other explicit Russian mode (available | connected) has
- Doublebuf: Required for smooth animation
- OpenGL: You can use pyopengl, but you cannot use pygame's plotting function.
There is also an optional depth parameter to control the depth of color display. Generally, you do not need to specify this parameter. You only need to use the default value.
If doublebuf is used, you need to use the flip function to display the drawn content to the screen.
>>> pygame.display.flip()