How to load the Spine in quick 3.3 and how to load the spine in quick3.3
Recently, the project needs to be upgraded to Quick 3.3, and Spine is used as an animation editor. Here we record the pitfalls encountered when loading the Spine with quick 3.3.
1. Spine version Problems
First, the Quick 3.3 Integrated version is not the latest official version, so this may encounter some strange problems, so here we recommend that you use Spine on github (https://github.com/EsotericSoftware/spine-runtimes)
When the latest version is used, it is quite easy to replace the version.
Download the Spine-runtimes file and copy the files in the following folder.
[1] All files under spine-c/src/spine
[2] All files under spine-c/include/spine
[3] spine-cocos2dx/3/src/spine all files
Overwrite all files in the official spine of quick 3.3
In this case, re-compile the project with VS, so that the latest version of Spine can be used in C ++.
2. Export the Spine function to Lua script
The above mentioned is the use of Spine in C ++, but the Lua code is required for the quick framework we use. Here we will talk about the tolua problem of Spine.
First of all, please refer to this article: http://blog.k-res.net/archives/1750.html
And the book "I understand the cocos2d-x" Chapter 18th also has a description of Lua-bindinge, here do not repeat.
Open the framework/cocos2d-x/tools/tolua under the project file and you will see a bunch. *. Ini files. These are all Spine code functions to be exported. Here, we will focus on [genbindings. py] and [README. mdown]
Readme. mdown is a help file, which focuses on using the Tolua tool on the window platform. You need to install the following tools:
1. python2.7.3
2. Install Python plug-in: pyyaml
3. Install Python plug-in: pycheetah
4. Install and set the android-ndk-r9b, and set the NDK_ROOT path
After installation, double-click genbindings. py to generate the Spine code for Lua.
3. Notes
Quick 3.3 renames some Spine code in the framework/cocos2d-x/cocos/scripting/lua-binding/manual/spine
Open the lua_cocos2dx_spine_manual.cpp file and you can find the code in it:
Static void extendCCSkeletonAnimation (lua_State * L)
{
Lua_pushstring (L, "sp. SkeletonAnimation ");
Lua_rawget (L, LUA_REGISTRYINDEX );
If (lua_istable (L,-1 ))
{
Tolua_function (L, "create", lua_cocos2dx_CCSkeletonAnimation_createWithFile );
Tolua_function (L, "registerSpineEventHandler", tolua_Cocos2d_CCSkeletonAnimation_registerSpineEventHandler00 );
Tolua_function (L, "unregisterSpineEventHandler", tolua_Cocos2d_CCSkeletonAnimation_unregisterSpineEventHandler00 );
Tolua_function (L, "setBlendFunc", tolua_spine_SkeletoneAnimation_setBlendFunc );
Tolua_function (L, "addAnimation", lua_cocos2dx_spine_SkeletonAnimation_addAnimation );
Tolua_function (L, "setAnimation", lua_cocos2dx_spine_SkeletonAnimation_setAnimation );
}
Lua_pop (L, 1 );
Because sp.SkeletonAnimation:create creat a LuaSkeletonAnimation object,so we need use LuaSkeletonAnimation typename for g_luaType*/ std::string typeName = typeid(LuaSkeletonAnimation).name(); g_luaType[typeName] = "sp.SkeletonAnimation"; g_typeCast["SkeletonAnimation"] = "sp.SkeletonAnimation";}
The key is tolua_function. You can see that createWithFile is replaced with create, and the registered script event is registerSpineEventHandler.
4. Callback
Remember not to delete the Spine Node object in the Event Callback, because after deleting itself, there will be other operations in the future.
My practice is: In update, set whether to delete a tag and determine whether to delete the spine Node object based on the tag. In the event response callback function, set the tag.
For Lua, update can be used for Schedule scheduling.