为Web平台编译
需求
要编译Web的导出模板,需要以下内容:
参见
有关Godot的SCons用法的一般概述,请参阅 构建系统介绍.
构建导出模板
Before starting, confirm that emcc
is available in your PATH. This is usually configured by the Emscripten SDK, e.g. when invoking emsdk activate
and source ./emsdk_env.sh
/emsdk_env.bat
.
打开终端并导航到引擎源代码的根目录.然后指示SCons构建JavaScript平台.为发布版本将 target
指定 release
,或为调试版本将 target
指定 release_debug
:
scons platform=javascript tools=no target=release
scons platform=javascript tools=no target=release_debug
默认情况下, JavaScript singleton 将被内置到引擎中.官方导出模板也启用了JavaScript单例.由于 eval()
调用可能是一个安全问题, javascript_eval
选项可以用来构建,而无需单例:
scons platform=javascript tools=no target=release javascript_eval=no
scons platform=javascript tools=no target=release_debug javascript_eval=no
现在,引擎将由Emscripten编译为WebAssembly.完成后,生成的文件将放在 bin
子目录中.针对发布版本的名字是 godot.javascript.opt.zip
,或针对调试版本的是 godot.javascript.opt.debug.zip
.
最后,将zip存档重命名为 webassembly_release.zip
以获取发布版本的模板:
mv bin/godot.javascript.opt.zip bin/webassembly_release.zip
调试模板的 webassembly_debug.zip
:
mv bin/godot.javascript.opt.debug.zip bin/webassembly_debug.zip
Threads and GDNative
The default export templates do not include threads and GDNative support for performance and compatibility reasons. See the export page for more info.
You can build the export templates using the option threads_enabled=yes
or gdnative_enabled=yes
to enable threads or GDNative support:
scons platform=javascript tools=no threads_enabled=yes target=release
scons platform=javascript tools=no threads_enabled=yes target=release_debug
scons platform=javascript tools=no gdnative_enabled=yes target=release
scons platform=javascript tools=no gdnative_enabled=yes target=release_debug
Once finished, the resulting file will be placed in the bin
subdirectory. Its name will have either the .threads
or .gdnative
suffix.
Finally, rename the zip archives to webassembly_release_threads.zip
and webassembly_release_gdnative.zip
for the release template:
mv bin/godot.javascript.opt.threads.zip bin/webassembly_threads_release.zip
mv bin/godot.javascript.opt.gdnative.zip bin/webassembly_gdnative_release.zip
And webassembly_debug_threads.zip
and webassembly_debug_gdnative.zip
for the debug template:
mv bin/godot.javascript.opt.debug.threads.zip bin/webassembly_threads_debug.zip
mv bin/godot.javascript.opt.debug.gdnative.zip bin/webassembly_gdnative_debugzip
Building the Editor
It is also possible to build a version of the Godot editor that can run in the browser. The editor version requires threads support and is not recommended over the native build. You can build the editor with:
scons platform=javascript tools=yes threads_enabled=yes target=release_debug
Once finished, the resulting file will be placed in the bin
subdirectory. Its name will be godot.javascript.opt.tools.threads.zip
. You can upload the zip content to your web server and visit it with your browser to use the editor.
Refer to the export page for the web server requirements.