spine獲取骨骼位置


time: 2015/07/23

版本:

/******************************************************************************
 * Spine Runtimes Software License
 * Version 2.1

 

1. 在C++中添加獲取骨骼的函數

(1)SkeletonAnimation.h

/* page@2015/07/23 Return bone point */
    virtual cocos2d::Vec2 getBonePosition(const char* boneName) const;

 

(2)SkeletonAnimation.cpp

Vec2 SkeletonAnimation::getBonePosition(const char* boneName) const
{
    spBone *pBone = findBone(boneName);
    if (pBone)
        return cocos2d::Vec2(pBone->worldX, pBone->worldY);
    return cocos2d::Vec2(0, 0);
}

 

2. 使用tolua導出lua接口函數

(1)打開tolua目錄

(2)把genbindings.py文件復制一份,重命名為genbindings_spine.py,修改其中一段代碼為

try:

        tolua_root = '%s/tools/tolua' % project_root
        output_dir = '%s/cocos/scripting/lua-bindings/auto' % project_root

        cmd_args = {'cocos2dx_spine.ini' : ('cocos2dx_spine', 'lua_cocos2dx_spine_auto')}
        target = 'lua'

* 也可以不改,直接使用genbindings.py文件,只是會慢很多

(3)cmd命令行下運行:python genbindings.py

(4)生成的文件

tolua_beginmodule(tolua_S,"SkeletonAnimation");
        tolua_function(tolua_S,"setStartListener",lua_cocos2dx_spine_SkeletonAnimation_setStartListener);
        tolua_function(tolua_S,"setTrackEventListener",lua_cocos2dx_spine_SkeletonAnimation_setTrackEventListener);
        tolua_function(tolua_S,"setTrackCompleteListener",lua_cocos2dx_spine_SkeletonAnimation_setTrackCompleteListener);
        tolua_function(tolua_S,"setTrackStartListener",lua_cocos2dx_spine_SkeletonAnimation_setTrackStartListener);
        tolua_function(tolua_S,"setCompleteListener",lua_cocos2dx_spine_SkeletonAnimation_setCompleteListener);
        tolua_function(tolua_S,"setTrackEndListener",lua_cocos2dx_spine_SkeletonAnimation_setTrackEndListener);
        tolua_function(tolua_S,"setEventListener",lua_cocos2dx_spine_SkeletonAnimation_setEventListener);
        tolua_function(tolua_S,"setMix",lua_cocos2dx_spine_SkeletonAnimation_setMix);
        tolua_function(tolua_S,"setEndListener",lua_cocos2dx_spine_SkeletonAnimation_setEndListener);
        tolua_function(tolua_S,"getBonePosition",lua_cocos2dx_spine_SkeletonAnimation_getBonePosition);         tolua_function(tolua_S,"clearTracks",lua_cocos2dx_spine_SkeletonAnimation_clearTracks);
        tolua_function(tolua_S,"clearTrack",lua_cocos2dx_spine_SkeletonAnimation_clearTrack);
    tolua_endmodule(tolua_S);


* 多了一個加紅的函數

3. 使用

local pos = arm:getBonePosition(tbPos)
                print("pos = ", pos.x, pos.y);


結果:

pos =     8.8648509979248    89.864677429199

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM