{"id":160,"date":"2025-02-27T15:31:54","date_gmt":"2025-02-27T07:31:54","guid":{"rendered":"http:\/\/blog.sayoung.xyz\/?p=160"},"modified":"2026-02-10T15:27:55","modified_gmt":"2026-02-10T07:27:55","slug":"%e5%ad%a6%e4%b9%a0%e6%97%a5%e5%bf%97godot%e9%9b%b6%e7%a2%8e%e7%9f%a5%e8%af%86%e7%82%b9%e8%8b%a5%e5%b9%b2","status":"publish","type":"post","link":"https:\/\/blog.sayoung.wang\/index.php\/2025\/02\/27\/%e5%ad%a6%e4%b9%a0%e6%97%a5%e5%bf%97godot%e9%9b%b6%e7%a2%8e%e7%9f%a5%e8%af%86%e7%82%b9%e8%8b%a5%e5%b9%b2\/","title":{"rendered":"\u5b66\u4e60\u65e5\u5fd7|Godot\u96f6\u788e\u77e5\u8bc6\u70b9\u82e5\u5e72"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u7a97\u53e3\u900f\u660e\u5316<\/h2>\n\n\n\n<p>\u5728\u9879\u76ee\u2192\u9879\u76ee\u8bbe\u7f6e\u2192\u663e\u793a\u2192\u7a97\u53e3\u4e2d\u52fe\u9009\u900f\u660e\u5316\u548c\u50cf\u7d20\u7ea7\u900f\u660e\u3002\u4e4b\u540e\u5728\u811a\u672c\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u5f85\u8865\u5b8c\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u9f20\u6807\u900f\u8fc7<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@onready var polygon_2d_2: Polygon2D = $Polygon2D\n\u2026\u2026\nDisplayServer.window_set_mouse_passthrough(polygon_2d_2.polygon)\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>\u4e4b\u524d\u5199\u7684\u7b14\u8bb0<\/summary>\n<p>\u7814\u7a76\u4e86\u534a\u5929\u603b\u7b97\u662f\u660e\u767d\u4e3a\u5565camara2D\u8282\u70b9\u548cPolygon2D\u8282\u70b9\u5728\u4e00\u8d77\u7528\u663e\u793a\u4e0d\u51fa\u4e86<\/p>\n\n\n\n<p>\u9996\u5148\u662f\u6211\u7528\u7684\u56fe\u662f\u4e00\u5f20\u50cf\u7d20\u56fe\uff0c\u539f\u59cb\u5927\u5c0f\u5f88\u5c0f\uff0c\u7528polygon\u6846\u9009\u540e\u663e\u793a\u5728\u7a97\u53e3\u4e2d\u7684\u5b9e\u9645\u5927\u5c0f\u4e5f\u5f88\u5c0f\u3002\u8981\u8c03\u6574\u6700\u7ec8\u663e\u793a\u7684\u5927\u5c0f\u4e0d\u80fd\u7528camara2D\u7684\u7f29\u653e\uff0c\u800c\u662f\u5fc5\u987b\u8c03\u6574\u56fe\u7247\u548c\u76f8\u5e94\u7684Polygon\u5927\u5c0f\uff0c\u5426\u5219\u663e\u793a\u51fa\u6765\u53ea\u6709\u56fe\u7247\u653e\u5927\u4e86\u800cpolygon\u8303\u56f4\u4e0d\u53d8\uff0c\u9020\u6210\u663e\u793a\u4e0d\u5168\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u5c31\u662fUP\u63d0\u5230\u7684\u539f\u70b9\u5bf9\u9f50\uff0c\u5728\u6846\u9009polygon\u8303\u56f4\u7684\u65f6\u5019\u4e00\u5b9a\u8981\u4fdd\u8bc1\u5b83\u548cCamara2D\u7684\u539f\u70b9\u5bf9\u9f50\uff0c\u5b8c\u6210\u540e\u518d\u79fb\u52a8polygon\u4e0d\u4f1a\u6709\u5f71\u54cd\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u8fd8\u6709\u4e00\u70b9\uff0c\u6709\u65f6\u5019\u900f\u660e\u5316\u4f1a\u5931\u6548\uff0c\u4e00\u822c\u5c06\u6e32\u67d3\u5668\u6539\u4e3a\u517c\u5bb9\u6a21\u5f0f\u5373\u53ef\u89e3\u51b3\u3002<\/p>\n<\/details>\n<\/blockquote>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u68c0\u6d4b\u9f20\u6807\u70b9\u51fb\u4f4d\u7f6e<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#Rect2\u77e9\u5f62\u533a\u57df\nfunc _input(event: InputEvent):\n\t# \u68c0\u6d4b\u53f3\u952e\u70b9\u51fb\n\tif event is InputEventMouseButton:\n\t\tif event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:\n\t\t\t# \u68c0\u67e5\u70b9\u51fb\u4f4d\u7f6e\u662f\u5426\u5728\u7279\u5b9a\u533a\u57df\u5185\n\t\t\tif Rect2(Vector2(100, 100), Vector2(200, 200)).has_point(event.position):\n\t\t\t\t# \u663e\u793a\u53f3\u952e\u83dc\u5355\n\t\t\t\tpopup_menu.popup(Rect2i(event.position, Vector2i(100, 100)))\n#Polygon2D\u591a\u8fb9\u5f62\u533a\u57df\nfunc _input(event: InputEvent):\n    if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:\n        # \u83b7\u53d6\u9f20\u6807\u4f4d\u7f6e\uff08\u76f8\u5bf9\u4e8e\u5f53\u524d\u8282\u70b9\u7684\u5750\u6807\u7cfb\uff09\n        var mouse_pos = get_local_mouse_position()\n        # \u68c0\u6d4b\u70b9\u662f\u5426\u5728\u591a\u8fb9\u5f62\u5185\n        if Geometry2D.is_point_in_polygon(mouse_pos, polygon_points):\n            # \u663e\u793a\u53f3\u952e\u83dc\u5355\n            popup_menu.popup(Rect2i(event.global_position, Vector2i(100, 100)))\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u7a97\u53e3\u900f\u660e\u5316 \u5728\u9879\u76ee\u2192\u9879\u76ee\u8bbe\u7f6e\u2192\u663e\u793a\u2192\u7a97\u53e3\u4e2d\u52fe\u9009\u900f\u660e\u5316\u548c\u50cf\u7d20\u7ea7\u900f\u660e\u3002\u4e4b\u540e\u5728\u811a\u672c\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a \u9f20\u6807\u900f\u8fc7 \u68c0\u6d4b\u9f20 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[17],"class_list":["post-160","post","type-post","status-publish","format-standard","hentry","category-11","tag-godot"],"_links":{"self":[{"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/posts\/160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":2,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/posts\/160\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}