• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

python 搞代码 4年前 (2022-01-07) 53次浏览 已收录 0个评论

这篇文章主要介绍了python中pygame针对游戏窗口的显示方法,以完整实例形式较为详细的分析了pygame响应键盘按键改变窗口显示效果的相关实现技巧,需要的朋友可以参考下

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

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

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

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

上面给出了一个简单的例子,当然在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<strong style="color:transparent">来源gaodaima#com搞(代@码网</strong>.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' : '[email protected]', 'Version' : '1.0'} BG_IMAGE = 'C://py//bg.png-600' 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针对游戏窗口的显示方法实例分析(附源码)的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python中pygame针对游戏窗口的显示方法实例分析(附源码)

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址