cool hit counter pygame series_game window display strategy_Intefrankly

pygame series_game window display strategy


In this blog, I will give a demo demonstration of.

When we press the 'f' key on the keyboard, the window of the demo will switch to both full screen display and default display display modes

And in the background we can see the relevant information output:

A simple example is given above, but of course there is a more authoritative description of the display strategy in the official pygame documentation at

http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode

'''
   pygame.FULLSCREEN    create a fullscreen display
   pygame.DOUBLEBUF     recommended for HWSURFACE or OPENGL
   pygame.HWSURFACE     hardware accelerated, only in FULLSCREEN
   pygame.OPENGL        create an opengl renderable display
   pygame.RESIZABLE     display window should be sizeable
   pygame.NOFRAME       display window will have no border or controls
'''

==========================================================

Code section.

==========================================================

 1 #pygame fullscreen
 2 
 3 import os, pygame
 4 from pygame.locals import *
 5 from sys import exit
 6 
 7 '''
 8 pygame.display.set_mode():
 9    pygame.FULLSCREEN    create a fullscreen display
10    pygame.DOUBLEBUF     recommended for HWSURFACE or OPENGL
11    pygame.HWSURFACE     hardware accelerated, only in FULLSCREEN
12    pygame.OPENGL        create an opengl renderable display
13    pygame.RESIZABLE     display window should be sizeable
14    pygame.NOFRAME       display window will have no border or controls
15 '''
16 
17 __author__ = {'name' : 'Hongten',
18               'mail' : 'hongtenzone@foxmail.com',
19               'blog' : 'http://www.cnblogs.com/hongten',
20               'Version' : '1.0'}
21 
22 BG_IMAGE = 'bg.png'
23 SCREEN_DEFAULT_SIZE = (500, 500)
24 pygame.init()
25 
26 #create the image path
27 bg_path = os.path.join('data', BG_IMAGE)
28 if not os.path.exists(bg_path):
29     print('The BackGround Image does not exist!')
30 
31 screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32)
32 bg = pygame.image.load(bg_path).convert()
33 
34 #full screen flag
35 full_screen = False
36 
37 while 1:
38     for event in pygame.event.get():
39         if event.type == QUIT:
40             exit()
41         if event.type == KEYDOWN:
42             #when press the 'f',then change the screen display model
43             if event.key == K_f:
44                 full_screen = not full_screen
45                 if full_screen:
46                     print('Open the Fullscreen model!')
47                 else:
48                     print('Open the Default model!')
49             if full_screen:
50                 #full screen display model
51                 screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, FULLSCREEN, 32)
52             else:
53                 #default model
54                 screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32)
55 
56         screen.blit(bg, (0, 0))
57         pygame.display.update()

E | hongtenzone@foxmail.com B |http://www.cnblogs.com/hongten


Recommended>>
1、When The Exterminators Bump Into What Technology Wants
2、Bitcoins Dangerous Quantum Computing Will Break Blockchains Two Main Fates
3、Ofo and Mobay rush to open up bikesharing data both say they are the first who do you support
4、CES 2019 concept car creates new ways to travel more Audi immersion system disrupts cockpit concept
5、AWE2018奇点汽车勾勒智慧出行蓝图

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号