命令行教學¶
有一些開發者喜歡到處使用命令行。Godot 設計成對這些開發者友善,下面列舉了所有讓你完全在命令行中作業的步驟。由於引擎幾乎不以來外部函式庫,所以啟動時間非常快速,便讓 Godot 也很適合在這種工作流程中使用。
備註
On Windows and Linux, you can run a Godot binary in a terminal by specifying its relative or absolute path.
On macOS, the process is different due to Godot being contained within an
.app
bundle (which is a folder, not a file). To run a Godot binary
from a terminal on macOS, you have to cd
to the folder where the Godot
application bundle is located, then run Godot.app/Contents/MacOS/Godot
followed by any command line arguments. If you've renamed the application
bundle from Godot
to another name, make sure to edit this command line
accordingly.
命令列參照說明¶
通用選項
Command |
說明 |
|
顯示所有可用的命令列選項。 |
|
顯示版本資訊。 |
|
使用詳細標準輸出 (Stdout) 模式。 |
|
靜默模式,不輸出任何標準輸出 (Stdout) 訊息。仍會顯示錯誤。 |
執行選項
Command |
說明 |
|
開啟編輯器而非執行場景(必須啟用 工具 )。 |
|
開啟專案管理員,即使已自動偵測到專案(必須啟用 工具 )。 |
|
首次迭代後退出。 |
|
使用指定的區域代碼(<locale> 為兩個字母的代碼)。詳細請參考 Locales 。 |
|
專案路徑(<directory> 內必須包含一個「project.godot」檔案)。 |
|
向上層資料夾搜尋「project.godot」檔案。 |
|
欲載入之 Pack (.pck) 檔。 |
|
算繪器執行緒模式(「unsafe」、「safe」、「separate」)。詳細請參考 執行緒模型 。 |
|
遠端檔案系統( |
|
音效驅動程式。先指定 |
|
視訊驅動程式。先指定 |
顯示選項
Command |
說明 |
|
指定全螢幕模式。 |
|
指定視窗最大化。 |
|
指定視窗模式。 |
|
指定永遠顯示於最上層之視窗。 |
|
指定視窗解析度。 |
|
指定視窗位置。 |
|
強制低 DPI 模式(僅限 macOS 與 Windows)。 |
|
Run with invisible window. Useful together with |
偵錯選項
備註
偵錯選項僅適用於編輯器與匯出樣板(但必須使用 debug
或 release_debug
來建置目標,詳細請參考 目標 )。
Command |
說明 |
|
除錯(本機標準輸出 (Stdout) 除錯工具)。 |
|
以 source::line,逗號分隔配對,無空白(顯示 %%20)來列出中斷點。 |
|
在腳本除錯工具中啟用分析。 |
|
遠端除錯( |
|
執行場景時顯示碰撞區域。 |
|
執行場景時顯示導航多邊形。 |
|
模擬 CPU 高負載(每幀延遲 <ms> 毫秒)。 |
|
強制時間縮放(值越早則越快,1.0 為正常速度)。 |
|
禁用算繪循環,將只在腳本內明確呼叫時才進行算繪。 |
|
若平台代碼支援,禁用 Crash Handler。 |
|
強制固定數 FPS。該設定將禁用即時同步。 |
|
在標準輸出上印出 FPS。 |
獨立工具
Command |
說明 |
|
執行腳本。 |
|
僅解析錯誤並退出(與 |
|
使用指定的匯出目標來匯出專案。若路徑以 .pck 或 .zip 結尾則只匯出 Main Pack(必須啟用 工具 )。 |
|
與 |
|
將引擎的 API 參照文件以 XML 格式傾印至指定的 <path> 路徑,若檔案存在則合併(必須啟用 工具 )。 |
|
禁用傾印基礎型別(與 |
|
建置腳本解決方案 (Solution)(如用於 C# 專案,必須啟用 工具 )。 |
|
產生用於 GDNative 綁定的 Godot API JSON 傾印(必須啟用 工具 )。 |
|
指定單元測試。先使用 |
|
與 |
路徑¶
建議將 Godot 二進位執行檔放置於 PATH 環境變數內,這樣在任何地方就只需要輸入 godot
即可執行。在 Linux 中可以將 Godot 二進位執行檔放在 /usr/local/bin
並確保該檔案命名為 godot
。
設定專案路徑¶
依據 Godot 的二進位執行檔放置位置以及目前工作目錄的不同,可能需要為下列指令設定專案路徑才可正確執行。
可以通過為第一個參數指定專案 project.godot
檔案所在的路徑來完成,如:
godot path_to_your_project/project.godot [other] [commands] [and] [args]
或是使用 --path
引數:
godot --path path_to_your_project [other] [commands] [and] [args]
舉例來說,用於匯出遊戲(下方會說明)的完整指令看起來會像這樣:
godot --path path_to_your_project --export my_export_preset_name game.exe
建立專案¶
可以通過將 Shell 導航至欲建立專案的位置並建立 project.godot 檔案來在命令列中建立專案。
mkdir newgame
cd newgame
touch project.godot
該專案即可以 Godot 開啟。
執行編輯器¶
可以使用 -e
旗標執行 Godot 來開啟編輯器。必須在專案目錄或其子目錄內完成,否則該指令會被忽略並開啟專案管理員。
godot -e
若已有建立並保存場景,則之後可使用相同的指令並以該場景作為參數來編輯。
godot -e scene.tscn
清除場景¶
Godot 對檔案系統友善,且不會建立額外的後設資料檔案。可使用 rm
來清除專案檔案。請確保沒有其他東西參照到該場景,否則開啟時會拋出錯誤。
rm scene.tscn
執行遊戲¶
欲執行遊戲,僅需於專案目錄或子目錄內執行 Godot。
godot
若需要測試特定的場景,則可將該場景傳入命令行。
godot scene.tscn
偵錯¶
在命令列中找出錯誤可能很困難。為此,可以通過加上 -d
引數來使用命令列除錯工具。該工具可以用於執行遊戲或場景。
godot -d
godot -d scene.tscn
匯出¶
Godot 亦支援自命令行匯出專案。對於 CI 環境(持續整合, Continuous Integration)設定特別有用。無周邊版本的 Godot (伺服器建置,無視訊功能)亦是最佳選擇。
godot --export "Linux/X11" /var/builds/project
godot --export Android /var/builds/project.apk
The preset name must match the name of an export preset defined in the
project's export_presets.cfg
file. If the preset name contains spaces or
special characters (such as "Windows Desktop"), it must be surrounded with quotes.
欲匯出除錯版本的遊戲,請使用 --export-debug
而非 --export
。其參數與用法皆相同。
如果只要匯出 PCK 檔案,可以將 --export
改成 --export-pack
選項,然後接上匯出預設設定的名稱與輸出路徑,並加上副檔名。輸出路徑的副檔名是依據套件格式判斷的,必須為 PCK 或 ZIP 其一。
警告
When specifying a relative path as the path for --export, --export-debug
or --export-pack, the path will be relative to the directory containing
the project.godot
file, not relative to the current working directory.
執行腳本¶
可欲命令列中執行簡單的 .gd
腳本。對於大型專案來說特別有用,如大量的素材轉換或自定匯入/匯出。
該腳本必須繼承 SceneTree
或 MainLoop
。
下列為一個簡單的 sayhello.gd
範例,用來說明如何運作:
#!/usr/bin/env -S godot -s
extends SceneTree
func _init():
print("Hello!")
quit()
以及如何執行:
# Prints "Hello!" to standard output.
godot -s sayhello.gd
若路徑中無 project.godot
,則目前的路徑將被視為目前的工作目錄(除非指定 --path
)。
在上方 sayhello.gd
範例中的第一行就是我們一般稱為 Shebang 的東西。若 Godot 的二進位執行檔有在 PATH
中,並且名稱為 godot
的話,則這行 Shebang 就能讓腳本在現代 Linux 發行版下執行,而 macOS 也可以:
# Mark script as executable.
chmod +x sayhello.gd
# Prints "Hello!" to standard output.
./sayhello.gd
若上方的這個範例無法在你使用的 Linux 或 macOS 版本中使用,也可以通過下列這個方法來直接讓 Shebang 從 Godot 儲存的地方執行:
#!/usr/bin/godot -s