首页 > 其他 > 详细

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

时间:2015-02-20 00:09:08      阅读:572      评论:0      收藏:0      [点我收藏+]

其实是想到什么就是学什么啦。(又跑到骨骼动画什么鬼)。。。

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 骨骼动画

原文:http://blog.csdn.net/dongshimou/article/details/43884031

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!