godot 篇-集成插件
集成 Spine 插件
Spine
官方并未提供 Godot
版的 Runtime
插件,需要集成第三方的插件 spine-runtime-for-godot,该插件基于 Godot自定义C++模块实现,未采用常规的 GDScript插件和 GDNative 插件机制实现,所以需要编译 Godot
源码进行集成。
下载 godot 源码
使用 Godot3.5 版本的源码进行集成,从 Github
上下载到本地
下载 spine-runtime-for-godot 源码
Github
上有开源的 spine-runtime-for-godot,支持 Spine 3.8/4.0
和 Godot3.x
版本
添加了 SpineSprite
节点,用于加载 Spine
的骨骼动画(需提供 .atlas
文件,图片文件和 .json
文件,atlas
资源会自动加载图片),并提供方法用于控制动画的播放,动画的混合等。同时提供相应的信号,用于处理骨骼动画发出的事件。
下载源码后,解压放入 Godot 源码目录 modules/spine_runtime
目录内
编译 Windows 版本 Godot
安装 python3.7
从官网下载 Python3.7 ,安装到指定路径
安装 scons
模块
1
2
3
4
5
6
7
8
9
10
11
| >pip install scons
Collecting scons
Downloading SCons-4.5.2-py3-none-any.whl (4.3 MB)
|████████████████████████████████| 4.3 MB 437 kB/s
Requirement already satisfied: setuptools in d:\tools\python37\lib\site-packages (from scons) (47.1.0)
Installing collected packages: scons
WARNING: The scripts scons-configure-cache.exe, scons.exe and sconsign.exe are installed in 'D:\tools\Python37\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed scons-4.5.2
WARNING: You are using pip version 20.1.1; however, version 23.2.1 is available.
You should consider upgrading via the 'D:\tools\Python37\python.exe -m pip install --upgrade pip' command.
|
安装 Cygwin
从官网下载 CygWin,解压到指定目录
编译
创建一个 bat
文件,写入以下内容
1
2
3
4
5
6
| set SCONS_CACHE=%~dp0scons_cache
set SCONS_CACHE_LIMIT=5000
set PATH=$PATH;..\mingw64\bin
set CXX=..\mingw64\bin\c++.exe
D:\tools\Python37\Scripts\scons.exe -j4 use_mingw=yes platform=windows
pause
|
双击执行 bat
文件进行编译,等待编译完成
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| >D:\tools\Python37\Scripts\scons.exe -j4 use_mingw=yes platform=windows target=release_debug
scons: Reading SConscript files ...
Configuring for Windows: target=release_debug, bits=default
Using MinGW
Scons cache enabled... (path: 'godot-3.5-stable\scons_cache')
Checking for C header file mntent.h... (cached) no
scons: done reading SConscript files.
scons: Building targets ...
[ 1%] Compiling ==> platform\windows\godot_windows.cpp
[ 1%] Compiling ==> platform\windows\context_gl_windows.cpp
[ 1%] Compiling ==> platform\windows\crash_handler_windows.cpp
[ 3%] Compiling ==> platform\windows\os_windows.cpp
[ 3%] Compiling ==> platform\windows\key_mapping_windows.cpp
...
[ 99%] Compiling ==> core\io\zip_io.cpp
[ 99%] Compiling ==> core\bind\core_bind.cpp
[100%] progress_finish(["progress_finish"], [])
[100%] Linking Static Library ==> core\libcore.windows.opt.tools.64.a
Ranlib Library ==> core\libcore.windows.opt.tools.64.a
[100%] Linking Program ==> bin\godot.windows.opt.tools.64.exe
[100%] scons: done building targets.
[Time elapsed: 00:23:20.746]
|
测试
打开编译成功的 godot
编辑器 godot-3.5-stable\bin\godot.windows.tools.64.exe
,创建一个 2D
项目
此时创建节点的对话框中出现了新的 Spine
相关节点
导入 spine
动画,可以正常显示
编译 Android 版 Godot 编辑器
安装 python3.7
从官网下载 Python3.7 ,安装到指定路径
安装 scons
模块
1
2
3
4
5
6
7
8
9
10
11
| >pip install scons
Collecting scons
Downloading SCons-4.5.2-py3-none-any.whl (4.3 MB)
|████████████████████████████████| 4.3 MB 437 kB/s
Requirement already satisfied: setuptools in d:\tools\python37\lib\site-packages (from scons) (47.1.0)
Installing collected packages: scons
WARNING: The scripts scons-configure-cache.exe, scons.exe and sconsign.exe are installed in 'D:\tools\Python37\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed scons-4.5.2
WARNING: You are using pip version 20.1.1; however, version 23.2.1 is available.
You should consider upgrading via the 'D:\tools\Python37\python.exe -m pip install --upgrade pip' command.
|
安装 Android SDK/NDK
在 AndroidDevTools 下载 sdk
和 ndk
,也可以在 Android
官网下载 NDK,安装或解压到指定目录
编译
godot
源码根目录创建一个 bat 文件
1
2
3
4
5
6
7
| set SCONS_CACHE=%~dp0scons_cache
set SCONS_CACHE_LIMIT=5000
set ANDROID_SDK_ROOT=D:\tools\android-sdk-windows
set ANDROID_NDK_ROOT=D:\tools\android-ndk-r21e
D:\tools\Python37\Scripts\scons.exe -j4 tools=true ndk_platform=android-21 platform=android android_arch=arm64v8 target=release_debug
pause
|
双击执行 bat
文件进行编译,等待编译完成
测试
将编译后的 apk
安装到 android
手机上,可以正常运行 spine
动画
集成 godot-tiled-importer 插件
godot-tiled-importer 是一个开源的 Tiled Map
地图导入插件,支持 Godot 3.x
,支持以下功能
- 将 Tiled 文件导入为 Godot 场景。 Tiled 中的每一层都是 Godot 中的一个 TileMap。
- 从 Tiled 独立图块集文件导入图块集。
- 地图的 .tmx (XML) 和 .json 格式。
- 切片集的 .tsx (XML) 和 .json 格式。
- 支持 Base64 编码地图。
- 支持图层压缩, zlib 和 gzip 都支持。
- 对象模板。
- 正交、等距、交错和六边形地图。
- 从图层导入可见性和不透明度。
- 导入碰撞/遮挡物/导航形状(基于平铺对象类型)。
- 支持单向碰撞形状。
- 自定义导入选项,例如是否启用 UV 剪辑。
- 支持图像层。
- 支持对象图层,形状导入为 StaticBody2D、Area2D 或 LightOcclusionr2D(取决于 type 属性),图块导入为 Sprite。
- 支持图层组,导入为 Node2D 。
- 地图、图层、图块集和对象的自定义属性作为元数据导入。图块上的自定义属性可以导入到 TileSet 资源中。
- 地图背景导入为视差背景(因此它实际上是无限的)
- 支持导入后脚本。
- 支持平铺动画。
- 瓷砖集的定制材料
- 设置每层的 Z 索引(通过 z_index 自定义属性)。
创建项目
打开 Godot
编辑器,创建一个 Test
项目
集成插件
从 godot-tiled-importer 或者 Godot-Asset-Library 下载插件代码
将它放入工程的 addon
目录
点击项目-> 项目设置,并启用插件
导入地图
导入地图比较简单,直接将 Tiled Map Editor
的 tmx
源文件和资源放入项目 res
目录即可,插件会自动将其转换为 Godot
资源。
双击打开 tmx
文件,可以正常显示地图,使用时只需要将 tmx
拖到场景中