quick lua 使用spine骨骼动画

看下下面两个文件

<spine/SkeletonRenderer.h>
<spine/SkeletonAnimation.h>

1.lua中创建方法:

sp.SkeletonAnimation:create(‘xxx.json’,'xxx.atlas', 1)  

实际上绑定过来的create 是createwithfile,可以参考 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);
        tolua_function(L, "replaceImage", lua_cocos2dx_spine_SkeletonAnimation_replaceImage);
        tolua_function(L, "getCustomBounds", lua_cocos2dx_spine_SkeletonAnimation_getCustomBounds);
    }
    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";
}

2.registerSpineEventHandler注册事件

SP_ANIMATION_START = 0
SP_ANIMATION_END = 1
SP_ANIMATION_COMPLETE = 2
SP_ANIMATION_EVENT = 3

3.setDebugBonesEnabled(true)   spine在调试模式,可以看到骨头的长度,骨点的位置

4.setDebugSlotsEnabled(true);设置查看每个骨头绑定的图片的大小,会用矩形框显示出来

5.setMix 让两个动作之间更加;流畅。单向的,所以我们要相互设置。最后一个是过渡时间

    self.aniNode2:setMix("move","idle",0.2)
    self.aniNode2:setMix("idle","move",0.2)

6.setTimeScale(0.1)

  默认是1.0 ,然后咱们可以设置动画播放的速度。比如人物的行走,美工做的时候,可以统一按照一个速度走。然后在程序里设置不同的速度。

7.换装(需要去学习)

(1)全部换装SetSkin

(2)局部换装

 

quick 3.3 "异步"加载Spine方案:http://blog.csdn.net/chenhaobright/article/details/44619633

http://blog.csdn.net/chenhaobright/article/details/44258399

原文地址:https://www.cnblogs.com/zhangfeitao/p/4531018.html