匯出專案¶
為何要匯出?¶
剛開始,Godot 中沒有能匯出專案的方法。開發人員需要編譯為適當的二進位檔,並為各個平台手動建立套件。
當更多開發人員 (甚至非程式設計師) 開始使用 Godot,或是當一間公司開始同時進行更多專案時,很明顯這就成了一個瓶頸。
在 PC 平台上¶
以 Godot 來發佈遊戲專案很簡單。只需要將 Godot 二進位檔放在跟 project.godot
同一個資料夾內,然後壓縮專案資料夾就好了。
說起來很容易,但有幾個原因讓開發人員並不想這麼做。第一種原因是,我們可能不想要發佈這麼多的檔案。有些開發者也可能不喜歡好奇使用者們都看遊戲是怎麼做的,其他開發者則覺得這樣發佈很不優雅。第二種原因則是開發人員可能偏好特別編譯的二進位檔。二進位檔的檔案比較小,最佳化比較好,而且也不包含如編輯器或除錯工具等工具。
Finally, Godot has a simple but efficient system for creating DLCs as extra package files.
在行動平台上¶
同樣的情況,搬到行動平台上就稍微糟糕一點了。要在這些平台上發佈專案,則必須為各個平台建置各自的二進位檔,並將遊戲資料一起新增到原生專案中。
這代表開發人員必須要在專案連匯出都還沒之前就熟悉各平台的 SDK,所以可能會很麻煩。雖然我們鼓勵大家學習各 SDK,但還沒準備好就強迫學習總是很讓人沮喪。
這種方法還有另一個問題:不同的裝置偏好以不同格式的資料來執行。主要的例子即為紋理壓縮。所有的 PC 硬體都使用 S3TC (BC) 壓縮,而且早在十年前就標準化了。但行動裝置卻使用不同的紋理壓縮格式,如 PVRTC (iOS) 或 ETC (Android)。
從命令行進行匯出¶
在正式環境中,適用於自動建置,在 Godot 中可以使用 --export
與 --export-debug
參數來從命令行進行匯出。但從命令行匯出依然需要匯出預設設定來指定匯出參數。該指令的基本呼叫方法如下:
godot --export "Windows Desktop" some_name.exe
This will export to some_name.exe
, assuming there is a preset
called "Windows Desktop" and the template can be found. (The export preset name
must be written within quotes if it contains spaces or special characters.)
The output path is relative to the project path or absolute;
it does not respect the directory the command was invoked from.
The output file extension should match the one used by the Godot export process:
Windows:
.exe
macOS:
.zip
(from all platforms) or.dmg
(only when exporting from macOS)..app
is not supported directly, although the generated ZIP archive contains an.app
bundle.Linux: Any extension (including none).
.x86_64
is typically used for 64-bit x86 binaries.HTML5:
.zip
Android:
.apk
iOS:
.zip
You can also configure it to export only the PCK or ZIP file, allowing a single exported main pack file to be used with multiple Godot executables. When doing so, the export preset name must still be specified on the command line:
godot --export-pack "Windows Desktop" some_name.pck
It is often useful to combine the --export
flag with the --path
flag, so that you do not need to cd
to the project folder before running
the command:
godot --path /path/to/project --export "Windows Desktop" some_name.exe
也參考
See 命令行教學 for more information about using Godot from the command line.
PCK v.s. ZIP 打包檔案格式¶
不同格式都各有其利弊。PCK 是預設的格式,且建議用於大多數情況。但依據需求的不同,使用者可能會想用 ZIP 壓縮檔。
PCK 格式:
未經壓縮的格式。檔案大小較大,但讀寫較快。
在使用者的作業系統上通常沒有附帶能讀寫 PCK 格式的工具。但有一些 第三方工具 可以解包與建立 PCK 檔案。
ZIP 格式:
經過壓縮。檔案大小較小,但讀寫較慢。
使用者的作業系統上通常會附帶可讀寫 ZIP 格式的工具。適合用於製作較易進行 Mod 的遊戲 (也請一併參考 匯出套件、修正檔與 Mod )。
警告
Due to a known bug, when using a ZIP file as a pack file, the exported binary will not try to use it automatically. Therefore, you have to create a launcher script that the player can double-click or run from a terminal to launch the project:
:: launch.bat (Windows)
@echo off
my_project.exe --main-pack my_project.zip
# launch.sh (Linux)
./my_project.x86_64 --main-pack my_project.zip
Save the launcher script and place it in the same folder as the exported binary.
On Linux, make sure to give executable permissions to the launcher script using
the command chmod +x launch.sh
.