pygame系列_游戏窗口显示策略

在这篇blog中,我将给出一个demo演示:

当我们按下键盘的‘f’键的时候,演示的窗口会切换到全屏显示和默认显示两种显示模式

并且在后台我们可以看到相关的信息输出:

hongten_pygame

上面给出了一个简单的例子,当然在pygame的官方文档中有对显示策略的更权威的说明:

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
'''
复制代码

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

代码部分:

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

复制代码
 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()
复制代码

 

转载于:https://www.cnblogs.com/liuzhi/p/3975785.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值