您的位置:首页 > 产品设计 > UI/UE

quick 3.3载入Spine问题

2017-06-18 09:05 190 查看
近期项目要升级到Quick 3.3, 而且使用了Spine作为动画编辑器, 在此把升级过程中。有关quick 3.3 载入Spine遇到的坑在此记录一下。

1、Spine版本号问题

首先Quick 3.3集成的版本号并不是是官方最新版本号, 于是这就有可能会遇到一些比較奇怪的问题, 所以在这里建议最好使用Spine在github(https://github.com/EsotericSoftware/spine-runtimes

上使用最新版本号,版本号的替换也是相当easy。

先下载Spine-runtimes。拷贝例如以下目录下的文件。

【1】spine-c/src/spine 下全部文件

【2】spine-c/include/spine下全部文件

【3】spine-cocos2dx/3/src/spine 下全部文件

将quick 3.3官方下的全部spine下的文件覆盖

此时,用VS重编项目,这样, 在C++版本号下,就能够使用最新版的Spine功能了

2、导出Spine功能到Lua脚本

上面说的是在C++版本号下使用Spine, 可是我们用的quick框架,须要用到Lua代码,这里就要讲一下Spine的tolua问题了。

首先,请參考一下这篇文章:http://blog.k-res.net/archives/1750.html

以及书籍《我所理解的cocos2d-x》第18章也对Lua-bindinge 有所描写叙述,在此不反复讲。

打开项目文件下 framework/cocos2d-x/tools/tolua下,能够看到一堆。*.ini文件,这些都是须要导出的Spine代码函数,这里重点关注一下【genbindings.py】、【README.mdown】

readme.mdown是帮助文件。里面重点讲到,使用Tolua工具在window平台。 须要安装例如以下工具:

1、python2.7.3

2、安装Python插件:pyyaml

3、安装Python插件:pycheetah

4、安装并设置android-ndk-r9b, 并设置NDK_ROOT路径

安装完了之后,双击genbindings.py就能够生成供Lua使用的Spine 代码了。

3、注意事项

quick 3.3将一些Spine代码又一次命名了, 在framework/cocos2d-x/cocos/scripting/lua-binding/manual/spine

打开lua_cocos2dx_spine_manual.cpp文件。能够在里面找到这么一段代码:

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";
}


关键看tolua_function。能够看到将createWithFile更换为create, 注冊脚本事件为registerSpineEventHandler

4、关于回调

切记不要在事件回调中,删除Spine节点对象, 由于删除自身之后。 兴许还会有其它操作。

我的做法是:在update中。设置一个能否够删除标记, 依据标记来推断是否删除spine节点对象,而事件响应回调函数中, 则是设置标记的。

至于Lua中,使用update, 能够使用Schedule调度.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: