神剑山庄资源网 Design By www.hcban.com

本文实例讲述了python中pygame针对游戏窗口的显示方法。分享给大家供大家参考,具体如下:

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

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

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

python中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
'''

代码部分:

#pygame fullscreen
import os, pygame
from pygame.locals import *
from sys import exit
'''
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
'''
__author__ = {'name' : 'Hongten',
       'mail' : 'hongtenzone@foxmail.com',
       'Version' : '1.0'}
BG_IMAGE = 'C://py//bg.png'
SCREEN_DEFAULT_SIZE = (500, 500)
pygame.init()
#create the image path
bg_path = os.path.join('data', BG_IMAGE)
if not os.path.exists(bg_path):
  print('The BackGround Image does not exist!')
screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32)
bg = pygame.image.load(bg_path).convert()
#full screen flag
full_screen = False
while 1:
  for event in pygame.event.get():
    if event.type == QUIT:
      exit()
    if event.type == KEYDOWN:
      #when press the 'f',then change the screen display model
      if event.key == K_f:
        full_screen = not full_screen
        if full_screen:
          print('Open the Fullscreen model!')
        else:
          print('Open the Default model!')
      if full_screen:
        #full screen display model
        screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, FULLSCREEN, 32)
      else:
        #default model
        screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32)
    screen.blit(bg, (0, 0))
    pygame.display.update()

完整实例代码代码点击此处本站下载。

希望本文所述对大家Python程序设计有所帮助。

标签:
python,pygame,游戏窗口,显示

神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com

评论“python中pygame针对游戏窗口的显示方法实例分析(附源码)”

暂无python中pygame针对游戏窗口的显示方法实例分析(附源码)的评论...

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。