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

首頁 > 編程 > Python > 正文

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

2020-01-04 17:56:33
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了python中pygame針對游戲窗口的顯示方法,以完整實例形式較為詳細的分析了pygame響應鍵盤按鍵改變窗口顯示效果的相關實現技巧,需要的朋友可以參考下

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

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

當我們按下鍵盤的‘f'鍵的時候,演示的窗口會切換到全屏顯示和默認顯示兩種顯示模式

并且在后臺我們可以看到相關的信息輸出:

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

上面給出了一個簡單的例子,當然在pygame的官方文檔中有對顯示策略的更權威的說明:

http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode

 

 
  1. ''
  2. pygame.FULLSCREEN create a fullscreen display 
  3. pygame.DOUBLEBUF recommended for HWSURFACE or OPENGL 
  4. pygame.HWSURFACE hardware accelerated, only in FULLSCREEN 
  5. pygame.OPENGL create an opengl renderable display 
  6. pygame.RESIZABLE display window should be sizeable 
  7. pygame.NOFRAME display window will have no border or controls 
  8. ''

代碼部分:

 

 
  1. #pygame fullscreen 
  2. import os, pygame 
  3. from pygame.locals import * 
  4. from sys import exit 
  5. ''
  6. pygame.display.set_mode(): 
  7. pygame.FULLSCREEN create a fullscreen display 
  8. pygame.DOUBLEBUF recommended for HWSURFACE or OPENGL 
  9. pygame.HWSURFACE hardware accelerated, only in FULLSCREEN 
  10. pygame.OPENGL create an opengl renderable display 
  11. pygame.RESIZABLE display window should be sizeable 
  12. pygame.NOFRAME display window will have no border or controls 
  13. ''
  14. __author__ = {'name' : 'Hongten'
  15. 'mail' : 'hongtenzone@foxmail.com'
  16. 'Version' : '1.0'
  17. BG_IMAGE = 'C://py//bg.png' 
  18. SCREEN_DEFAULT_SIZE = (500, 500) 
  19. pygame.init() 
  20. #create the image path 
  21. bg_path = os.path.join('data', BG_IMAGE) 
  22. if not os.path.exists(bg_path): 
  23. print('The BackGround Image does not exist!'
  24. screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32) 
  25. bg = pygame.image.load(bg_path).convert() 
  26. #full screen flag 
  27. full_screen = False 
  28. while 1: 
  29. for event in pygame.event.get(): 
  30. if event.type == QUIT: 
  31. exit() 
  32. if event.type == KEYDOWN: 
  33. #when press the 'f',then change the screen display model 
  34. if event.key == K_f: 
  35. full_screen = not full_screen 
  36. if full_screen: 
  37. print('Open the Fullscreen model!'
  38. else
  39. print('Open the Default model!'
  40. if full_screen: 
  41. #full screen display model 
  42. screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, FULLSCREEN, 32) 
  43. else
  44. #default model 
  45. screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE, 0, 32) 
  46. screen.blit(bg, (0, 0)) 
  47. pygame.display.update() 

完整實例代碼代碼點擊此處本站下載。

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 西藏| 泽库县| 鄂尔多斯市| 平顶山市| 获嘉县| 庄河市| 察哈| 彰化县| 南召县| 麻江县| 正镶白旗| 炉霍县| 都安| 白水县| 夏津县| 苍南县| 黑山县| 灵川县| 土默特左旗| 通州市| 区。| 湖北省| 峨眉山市| 丹阳市| 南漳县| 青州市| 逊克县| 武陟县| 定陶县| 永泰县| 华安县| 电白县| 临沂市| 仙游县| 奎屯市| 普安县| 黄冈市| 彭泽县| 乌兰县| 沭阳县| 昌乐县|