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

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

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

动画混合的功能,使动作衔接自然。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值