使用 JSB 对 原生 spine 添加 SpineBounds 支持

开发环境

系统:win7 64位
CocosCreator: 2.0.9

说明

这里只对 new sp.spine.SkeletonBounds().containsPoint() ,进行了绑定,其他函数请自行添加

   var _skeletonBounds = new sp.spine.SkeletonBounds();
   _skeletonBounds .update(spine._skeleton);                
   var region = _skeletonBounds .containsPoint(x, y);
   if(region){
   }

JSB参考

https://blog.csdn.net/u013654125/article/details/79576982
https://oedx.github.io/2019/07/03/cocos-creator-js-binding-auto/

添加 SpineBounds 类

在 jsb-default\frameworks\cocos2d-x\cocos\editor-support\spine-creator-support 下添加文件

SpineBounds.h (见附件)

SpineBounds.cpp (见附件)

修改 spine-cocos2dx.h

位置: frameworks\cocos2d-x\cocos\editor-support\spine-creator-support\spine-cocos2dx.h

    ....
    #include "spine-creator-support/CreatorAttachmentLoader.h"
    #include "spine-creator-support/SpineRenderer.h"
    #include "spine-creator-support/SpineAnimation.h"
    // 添加引用
    #include "spine-creator-support/SpineBounds.h"
    #include "middleware-adapter.h"
    ....

修改 Android.mk

位置: frameworks\cocos2d-x\cocos\editor-support\Android.mk

    ...
    spine-creator-support/SpineAnimation.cpp \
    spine-creator-support/SpineRenderer.cpp \
    #添加引用
    spine-creator-support/SpineBounds.cpp \
    spine-creator-support/spine-cocos2dx.cpp \
    ...

修改 cocos2dx_spine.ini

位置: frameworks\cocos2d-x\tools\tojs\cocos2dx_spine.ini

详情对比 cocos2dx_spine.ini (见附件)

修改 genbindings.py

位置: frameworks\cocos2d-x\tools\tojs\genbindings.py

        ......
        # just generate custom file
        cmd_args.clear()
        cmd_args["cocos2dx_spine.ini"] = ('cocos2dx_spine', 'jsb_cocos2dx_spine_auto')
        //添加以上 ,只对 spine 进行重新绑定
        target = 'spidermonkey'
        ......

执行脚本自动绑定

python genbindings.py

附件.zip (1.8 KB)

1赞