其实是想到什么就是学什么啦。(又跑到骨骼动画什么鬼)。。。
PS:学习历程啦,可能会有很多错误。
骨骼动画用的是spine 的样例了。spineboy 有两个动作 jump 和 walk。
在export的时候格式选择Json而且勾选Create atlas。 (安装路径,导入路径,导出路径不能有中文)
然后复制这三个文件 Json,atlas,png 到资源下面。
使用官网的用法
auto sap = new SkeletonAnimation("spineboy.Json","spineboy.atlas");
报错。如图。
貌似中文站的用法介绍还是3.0,而我正在使用的版本是3.4。
然后查看了 SkeletonAnimation.h 的源码。
在83 行。
源码:
难道是因为protected?没搞懂。。。
看了下源码发现前面还有这几种创建方法。
public: static SkeletonAnimation* createWithData (spSkeletonData* skeletonData); static SkeletonAnimation* createWithfile (const std::string& skeletonDatafile,spAtlas* atlas,float scale = 1); static SkeletonAnimation* createWithfile (const std::string& skeletonDatafile,const std::string& atlasfile,float scale = 1);
就用了第三种 (scale=1 缩放)
成功!
需要
#include <spine/spine-cocos2dx.h>#include "spine/spine.h"using namespace spine;
auto sap = SkeletonAnimation::createWithfile("spineboy.Json","spineboy.atlas"); sap->addAnimation(0,"walk",true); //sap->addAnimation(0,"jump",false); Size Winsize=Director::getInstance()->getWinSize(); sap->setposition(Vec2(Winsize.wIDth/2,Winsize.height/4)); this->addChild(sap);
动作之间衔接不自然的时候就需要用到
voID setMix(const char *fromAnimation,const char *toAnimation,float duration);动画混合的功能,使动作衔接自然。 总结
以上是内存溢出为你收集整理的Cocos2d-x 3.x 练习 2 骨骼动画全部内容,希望文章能够帮你解决Cocos2d-x 3.x 练习 2 骨骼动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)