Surface and Screen

Source: Internet
Author: User
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()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.