码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-02-20 00:10:15      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:cocos2d-x 3.x   骨骼动画   

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!