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

 

posted @   上山老人  阅读(3762)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示