

{"id":126,"date":"2021-06-23T23:27:03","date_gmt":"2021-06-23T15:27:03","guid":{"rendered":"https:\/\/www.52dixiaowo.com\/python\/?p=126"},"modified":"2021-06-24T01:45:23","modified_gmt":"2021-06-23T17:45:23","slug":"pygame-%e9%a3%9e%e6%9c%ba%e5%a4%a7%e6%88%98-%e7%aa%97%e5%8f%a3%e7%bb%98%e5%88%b6","status":"publish","type":"post","link":"https:\/\/www.52dixiaowo.com\/python\/post-126.html","title":{"rendered":"pygame \u98de\u673a\u5927\u6218 \u7a97\u53e3\u7ed8\u5236"},"content":{"rendered":"\n<p>\u5728pyGameAricraft\u9879\u76ee\u4e2d, \u65b0\u5efa\u4e00\u4e2amain.py\u6587\u4ef6 ( pycharm\u9879\u76ee\u9ed8\u8ba4\u5c31\u6709 )<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u6587\u4ef6\u5c06\u4f5c\u4e3a\u7a0b\u5e8f\u5165\u53e3, \u9996\u5148\u5728main.py\u642d\u5efa\u4e00\u4e9b\u57fa\u7840\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame   #\u5bfc\u5165pygame\u6a21\u5757\n\npygame.init()   #pygame\u521d\u59cb\u5316\n\nprint(\"\u6e38\u620f\u8fd0\u884c\u4e2d\")\n\npygame.quit()    #pygame\u7ed3\u675f<\/code><\/pre>\n\n\n\n<p>pygame\u7684init\u662f\u521d\u59cb\u5316pygame\u6240\u6709\u6a21\u5757, quit\u662f\u7ed3\u675f\u7a0b\u5e8f<\/p>\n\n\n\n<h2>\u77e9\u5f62\u7c7b<\/h2>\n\n\n\n<p>\u6211\u4eec\u5c06\u4f7f\u7528\u4e00\u4e2a\u5927\u7684\u77e9\u5f62\u7a97\u53e3, \u4f5c\u4e3a\u6e38\u620f\u7684\u7a97\u53e3, \u5bbd480, \u9ad8700<\/p>\n\n\n\n<p>pygame\u63d0\u4f9b\u4e86\u4e00\u4e2apygame.Rect\u7c7b\u7528\u4e8e\u63cf\u8ff0\u77e9\u5f62\u533a\u57df<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Rect(x, y, width, height) -> Rect<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d\u5750\u6807\u539f\u70b9\u4e3ax, y, \u800c\u5bbd, \u9ad8\u53ef\u4ee5\u7528 size \u8868\u793a<\/p>\n\n\n\n<h2>\u521b\u5efa\u6e38\u620f\u4e3b\u7a97\u53e3<\/h2>\n\n\n\n<p>pygame\u6709\u4e00\u4e2a display \u6a21\u5757, \u7528\u4e8e\u521b\u5efa\u3001\u7ba1\u7406\u6e38\u620f\u7a97\u53e3<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><tbody><tr><td>pygame.display.set_mode()<\/td><td>\u521d\u59cb\u5316\u6e38\u620f\u7a97\u53e3<\/td><\/tr><tr><td>pygame.display.update()<\/td><td>\u5237\u65b0\u6e38\u620f\u7a97\u53e3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>set_mode\u65b9\u6cd5<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set_mode(resolution=(0,0), flags=0, depth=0) -> Surface<\/code><\/pre>\n\n\n\n<p>\u53c2\u6570\u8bf4\u660e<\/p>\n\n\n\n<ul><li>resolution\u6307\u5b9a\u5c4f\u5e55\u7684<em>\u5bbd<\/em>\u548c<em>\u9ad8<\/em>, \u9ed8\u8ba4\u5927\u5c0f\u5168\u5c4f<\/li><li>flags\u53c2\u6570\u6307\u5b9a\u5c4f\u5e55\u7684\u9644\u52a0\u9009\u9879, \u53ef\u4ee5\u4e0d\u4f20\u9012<\/li><li>depth\u53c2\u6570\u8868\u793a\u989c\u8272\u4f4d\u6570, \u9ed8\u8ba4\u81ea\u52a8\u5339\u914d<\/li><\/ul>\n\n\n\n<p>\u8fd4\u56de\u503c, \u53ef\u4ee5\u7406\u89e3\u4e3a\u4e3b\u7a97\u53e3\u5bf9\u8c61, \u4e14\u5fc5\u987b\u63a5\u63a5\u6536\u8fd9\u4e2a\u5b9e\u4f8b, \u540e\u7eed\u8fd8\u9700\u8981\u64cd\u4f5c\u5b83<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>screen = pygame.display.set_mode((480, 700))<\/code><\/pre>\n\n\n\n<p>\u6b64\u5916, \u5728\u7a0b\u5e8f\u8fd0\u884c\u671f\u95f4, \u5e94\u8be5\u662f\u4e00\u4e2a\u5faa\u73af, \u5426\u5219\u7a97\u53e3\u4e00\u95ea\u800c\u8fc7<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while True:\n    pass<\/code><\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765, \u6211\u4eec\u7ed9\u7a97\u53e3\u7ed8\u5236\u80cc\u666f, \u5148\u4f7f\u7528pygame.image.load\u52a0\u8f7d\u56fe\u7247, \u7136\u540e\u7ed8\u5236, \u5237\u65b0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bg = pygame.image.load(\".\/images\/background.png\")\n\nscreen.blit(bg, (0,0))  #\u7ed8\u5236, \u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u56fe\u7247\u4f4d\u7f6e\n\npygame.display.update()  #\u5237\u65b0\u5c4f\u5e55<\/code><\/pre>\n\n\n\n<p>\u8fd8\u9700\u8981\u7ed8\u5236\u5df1\u65b9\u98de\u673a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hero = pygame.image.load(\".\/images\/me1.png\")\n\nscreen.blit(hero, (200, 500))\n\npygame.display.update()  #\u5237\u65b0\u5c4f\u5e55<\/code><\/pre>\n\n\n\n<p>pygame.display.update\u65b9\u6cd5\u662f\u5237\u65b0\u5c4f\u5e55, \u53ea\u9700\u8981\u5728\u663e\u793a\u524d\u5237\u65b0\u4e00\u6b21\u5373\u53ef<\/p>\n\n\n\n<h2>\u4ee3\u7801\u5c0f\u7ed3<\/h2>\n\n\n\n<p>\u672c\u5c0f\u8282, \u4fee\u6539\u540e\u7684main.py\u4ee3\u7801\u5982\u4e0b:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame as pg  #\u5bfc\u5165pygame\u6a21\u5757, \u7b80\u5316\u6a21\u5757\u540dpg\n\npg.init()   #pygame\u521d\u59cb\u5316\n\n#\u5b9e\u4f8b\u5316\u7a97\u53e3\nscreen = pg.display.set_mode((480, 700))\n\n#\u7ed8\u5236\u80cc\u666f\nbg = pg.image.load(\".\/images\/background.png\")\nscreen.blit(bg, (0,0))  #\u7ed8\u5236, \u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u56fe\u7247\u4f4d\u7f6e\n\n#\u7ed8\u5236\u5df1\u65b9\u98de\u673a\nhero = pg.image.load(\".\/images\/me1.png\")\nscreen.blit(hero, (200, 500))\npg.display.update()  #\u5237\u65b0\u5c4f\u5e55\n\nwhile True:\n    pass\n\npg.quit()    #pygame\u7ed3\u675f<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728pyGameAricraft\u9879\u76ee\u4e2d, \u65b0\u5efa\u4e00\u4e2amain.py\u6587\u4ef6 ( pycharm\u9879\u76ee\u9ed8\u8ba4\u5c31\u6709 ) \u8fd9\u4e2a\u6587&hellip; <a href=\"https:\/\/www.52dixiaowo.com\/python\/post-126.html\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">pygame \u98de\u673a\u5927\u6218 \u7a97\u53e3\u7ed8\u5236<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/www.52dixiaowo.com\/python\/wp-json\/wp\/v2\/posts\/126"}],"collection":[{"href":"https:\/\/www.52dixiaowo.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52dixiaowo.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52dixiaowo.com\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52dixiaowo.com\/python\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":0,"href":"https:\/\/www.52dixiaowo.com\/python\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.52dixiaowo.com\/python\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52dixiaowo.com\/python\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52dixiaowo.com\/python\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}