国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python中pygame針對游戲窗口的顯示方法實例分析(附源碼)

2019-11-25 17:02:26
字體:
來源:轉載
供稿:網友

本文實例講述了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 fullscreenimport os, pygamefrom 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 pathbg_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 flagfull_screen = Falsewhile 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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌拉特前旗| 正定县| 台北市| 苍山县| 刚察县| 胶州市| 台北市| 如东县| 阳朔县| 屏南县| 巧家县| 五家渠市| 临西县| 安新县| 孝义市| 安国市| 万山特区| 武川县| 电白县| 三门县| 宿迁市| 定兴县| 长宁区| 顺义区| 明溪县| 鸡西市| 成都市| 阿克| 清流县| 永新县| 洪江市| 山丹县| 阿克苏市| 阿克陶县| 武强县| 三穗县| 乐平市| 衡阳县| 修武县| 区。| 湖南省|