Up to date
This page is up to date for Godot 4.3.
If you still find outdated information, please open an issue.
類別參照手冊
本頁面將介紹如何編寫類參考手冊。你會學到去哪裡為 Godot 內建節點型別的類、方法、屬性編寫新的描述。
也參考
要學習如何使用 Git 版本控制系統向 Godot 專案提交你的修改,請參見 參與貢獻類別參照文件。
每個類的參考文件都被包含在一個如下的 XML 檔中:
<class name="Node2D" inherits="CanvasItem" version="4.0">
<brief_description>
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
</brief_description>
<description>
A 2D game object, with a transform (position, rotation, and scale). All 2D nodes, including physics objects and sprites, inherit from Node2D. Use Node2D as a parent node to move, scale and rotate children in a 2D project. Also gives control of the node's render order.
</description>
<tutorials>
<link title="Custom drawing in 2D">https://docs.godotengine.org/en/latest/tutorials/2d/custom_drawing_in_2d.html</link>
<link title="All 2D Demos">https://github.com/godotengine/godot-demo-projects/tree/master/2d</link>
</tutorials>
<methods>
<method name="apply_scale">
<return type="void">
</return>
<argument index="0" name="ratio" type="Vector2">
</argument>
<description>
Multiplies the current scale by the [code]ratio[/code] vector.
</description>
</method>
[...]
<method name="translate">
<return type="void">
</return>
<argument index="0" name="offset" type="Vector2">
</argument>
<description>
Translates the node by the given [code]offset[/code] in local coordinates.
</description>
</method>
</methods>
<members>
<member name="global_position" type="Vector2" setter="set_global_position" getter="get_global_position">
Global position.
</member>
[...]
<member name="z_index" type="int" setter="set_z_index" getter="get_z_index" default="0">
Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others.
</member>
</members>
<constants>
</constants>
</class>
各個類別都有一個簡短說明與長說明。簡短說明位於頁面頂部,而完整的長說明則位於方法、變數與常數列表下方。方法、成員變數、常數與訊號都放在個別分類或不同 XML 節點內。請從 Godot 的原始碼中瞭解這些功能各自如何運作,並填寫相應的 <descrioption>。
你會想要在 Godot 的原始程式碼中學習它們都有什麼用。然後補全或者完善這些標籤中的文字:
<brief_description>
說明
PI(圓周率)常數。
<method>`(在其 `<description> 標籤中;返回型別和參數不帶單獨的文件字串)
<member>
<signal>`(在其 `<description> 標籤中;參數不帶單獨的文件字串)
PI(圓周率)常數。
請以清晰明瞭的文字撰寫。務必遵守 撰寫方針 以保持說明簡短且容易閱讀。在簡介中 請不要保留空行 :在 XML 檔中每一行都會開新段落。
如果編輯類別 XML
請編輯 doc/classes/ 內所選類別的檔案來更新類別參照文件。該資料夾包含了用於各個類別的 XML 檔。這些 XML 中列出了可在類別參照文件中找到的常數與方法。Godot 會自動產生並更新 XML 檔。
備註
遊戲引擎中某些模組的 XML 檔在 modules/<模組名稱>/doc_classes/ 目錄下。
使用慣用的編輯器開啟 XML 檔。若使用程式碼編輯器,請確保不要更改到縮排樣式:XML 使用 Tab 資源,BBCode 風格的區塊中則使用 4 個空格。詳情見下方說明。
要檢查你所做出的修改在生成後的文件中是否正確,請在 doc/ 資料夾中執行命令 make rst。這樣就會將 XML 檔轉換為線上文件的格式,存在錯誤時會有錯誤報告。
你也可以自行建構 Godot 然後在內建的類參考手冊中打開被修改的頁面。引擎的編譯方法請查看 compilation guide。
請使用 Vim, Atom, Code, Notepad++ 或其他類似的編輯器來快速編輯檔案。可使用搜尋功能來快速找到類別。
小訣竅
如果您使用 Visual Studio Code,則可以安裝 vscode-xml 擴充 <https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml> 來糾察 XML 檔案的類引用。
Marking API as deprecated/experimental
To mark an API as deprecated or experimental, you need to add the corresponding XML attribute. The attribute value must be a message explaining why the API is not recommended (BBCode markup is supported) or an empty string (the default message will be used). If an API element is marked as deprecated/experimental, then it is considered documented even if the description is empty.
<class name="Parallax2D" inherits="Node2D" experimental="This node is meant to replace [ParallaxBackground] and [ParallaxLayer]. The implementation may change in the future." xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
[...]
</class>
<constant name="RESPONSE_USE_PROXY" value="305" enum="ResponseCode" deprecated="Many clients ignore this response code for security reasons. It is also deprecated by the HTTP standard.">
HTTP status code [code]305 Use Proxy[/code].
</constant>
<member name="auto_translate" type="bool" setter="set_auto_translate" getter="is_auto_translating" deprecated="Use [member Node.auto_translate_mode] instead.">
Toggles if any text should automatically change to its translated version depending on the current locale.
</member>
<method name="get_method_call_mode" qualifiers="const" deprecated="Use [member AnimationMixer.callback_mode_method] instead.">
<return type="int" enum="AnimationPlayer.AnimationMethodCallMode" />
<description>
Returns the call mode used for "Call Method" tracks.
</description>
</method>