最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2015年11月11日 12:48:15   作者:Hongten  
這篇文章主要介紹了python中pygame針對(duì)游戲窗口的顯示方法,以完整實(shí)例形式較為詳細(xì)的分析了pygame響應(yīng)鍵盤(pán)按鍵改變窗口顯示效果的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了python中pygame針對(duì)游戲窗口的顯示方法。分享給大家供大家參考,具體如下:

在這篇教程中,我將給出一個(gè)demo演示:

當(dāng)我們按下鍵盤(pán)的‘f'鍵的時(shí)候,演示的窗口會(huì)切換到全屏顯示和默認(rèn)顯示兩種顯示模式

并且在后臺(tái)我們可以看到相關(guān)的信息輸出:

上面給出了一個(gè)簡(jiǎn)單的例子,當(dāng)然在pygame的官方文檔中有對(duì)顯示策略的更權(quán)威的說(shuō)明:

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()

完整實(shí)例代碼代碼點(diǎn)擊此處本站下載。

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

松潘县| 镇康县| 静乐县| 阿荣旗| 拉萨市| 双峰县| 绥棱县| 监利县| 丰镇市| 玉门市| 新巴尔虎左旗| 满城县| 凤阳县| 鹤庆县| 台东县| 朝阳县| 宁国市| 临沂市| 乡城县| 内乡县| 微山县| 张家港市| 雅江县| 沙洋县| 广昌县| 扶绥县| 柳州市| 金川县| 喀喇沁旗| 沧源| 石家庄市| 永兴县| 焦作市| 凤阳县| 万州区| 博兴县| 舞钢市| 当雄县| 蛟河市| 长沙市| 错那县|