您的位置:首页 > 移动开发 > Cocos引擎

Cocos2d-x 3.x 练习 2 骨骼动画

2015-02-19 23:08 435 查看
其实是想到什么就是学什么啦。(又跑到骨骼动画什么鬼)。。。

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);


动画混合的功能,使动作衔接自然。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: