python中pygame针对游戏窗口的显示方法实例分析(附源码)
作者:Hongten 时间:2022-04-27 11:35:12
本文实例讲述了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.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
0
投稿
猜你喜欢
设计规范有谱么?
2008-06-06 12:28:00
详解如何使用Python实现删除重复文件
2022-08-14 04:33:54
Python中的复杂数据类型(list、tuple)
2023-06-07 10:10:19
如何设置SQL Server数据库全文索引服务
2009-01-13 13:46:00
代码详解Python的函数基础(1)
2023-08-16 17:47:22
解决Python正则表达式匹配反斜杠''\\''问题
2022-06-19 09:10:55
Python利用第三方模块实现压缩css文件
2023-04-28 07:21:02
将一个图片以二进制值的形式存入Xml文件中
2008-09-04 11:24:00
Python完成毫秒级抢淘宝大单功能
2023-09-29 04:14:54
回顾Javascript React基础
2023-07-13 00:57:00
详解Python中的各种函数的使用
2022-03-23 22:09:52
如何取得刚添加的记录自动增加的ID?
2010-01-18 20:55:00
基于Python实现自动化生成数据报表
2021-11-07 00:42:16
python 读取目录下csv文件并绘制曲线v111的方法
2022-08-21 16:05:34
python 通过exifread读取照片信息
2022-12-09 13:44:53
python魔法方法-自定义序列详解
2022-10-08 08:56:12
Python查找不限层级Json数据中某个key或者value的路径方式
2023-07-08 02:39:43
swfupload上传使用代码说明ASP版
2011-11-27 09:34:32
Python 面向对象编程详解
2023-06-25 05:24:23
python中列表的切片与修改知识点总结
2023-08-29 00:49:08