[pygame learning_5] window design

1 Introduction

The window is the interactive interface of the game. Generally, we will encounter design requirements such as adjustable window size, borderless window, full-screen display, minimized design, name change, and icon change.

 Screen drawing has the following important functions:

 2. Screen mode function

pygame.display.set.mode

#print(pygame.display.Info())
#screen = pygame.display.set_mode(size, pygame.RESIZABLE)  #窗口大小可调
#screen = pygame.display.set_mode(size, pygame.NOFRAME)  #窗口无边框
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)  #窗口全屏显示

 Each display method must cooperate with the corresponding processing mechanism.

When the size is adjustable, there must be a response to size changes. The borderless mode and full-screen mode should design the game exit method, and the full-screen mode should pay attention to the resolution design.

Press Esc to exit full screen mode:

            elif event.key == pygame.K_ESCAPE:
                sys.exit()

3. Screen information function

 Adaptively modify the game screen display information after the window size is modified:

        elif event.type == pygame.VIDEORESIZE:
            size = width, height = event.size[0], event.size[1]
            screen = pygame.display.set_mode(size, pygame.RESIZABLE)

4. Window title and icon design

Title Design:

pygame.display.set_caption

 pygame.display.get_caption

pygame.display.set_caption("Pygame壁球")

 Icon design:

pygame.display.set_icon

 5. Screen control and refresh function

Screen control : Control whether the game is paused according to the information on the screen.

pygame.display.get_active()

    if pygame.display.get_active(): # 只有窗体是激活的,小球才移动。
        ballrect = ballrect.move(speed)

Screen refresh function: There are two types as follows

 The former updates the entire screen information, while the latter only needs to update the information of moving individuals. For the excellent fixed scene, the latter is recommended.

Guess you like

Origin blog.csdn.net/weixin_44727682/article/details/128498396