Cocos2dx v3.2骨骼动画加载学习

Cocos2dx v3.2骨骼动画加载学习,第1张

概述一、使用Cocos Studio之前需要导入GUI、Extensions、CocosStudio的类库 右击解决方案选择添加现有项目添加这三个库文件导入成功效果如下 二、选择工程右键选择 属性-》通用属性-》添加新引用 勾选所添加库的lib选项效果图如下,完成后效果如下 三、添加附加包含目录 右键选择项目属性-》配置属性-》c/c++-》附加包含目录-》下拉按钮选择编辑 在附加包含目录中添加 $(

一、使用Cocos Studio之前需要导入GUI、Extensions、Cocosstudio的类库

右击解决方案选择添加现有项目添加这三个库文件导入成功效果如下

二、选择工程右键选择 属性-》通用属性-》添加新引用

勾选所添加库的lib选项效果图如下,完成后效果如下


三、添加附加包含目录

右键选择项目属性-》配置属性-》c/c++-》附加包含目录-》下拉按钮选择编辑

在附加包含目录中添加

$(EngineRoot) extensions需要

$(EngineRoot)cocos\editor-support\ cocosstudio需要

$(EngineRoot)cocos\editor-support\cocostudio cocosstudio需要

效果图


四、代码实现

在Cocos2d-x程序中使用Cocos Studio动画首先需要包含相关头文件,如下:

1 2 #include "cocostudio/CocoStudio.h" using namespace cocostudio;

五、主要API及使用方法

骨骼动画学习

3.0

ArmatureDataManager::getInstance()->addArmaturefileInfo("zhujue.ExportJson");

armature = Armature::create("zhujue");

armature->getAnimation()->playWithIndex(0);

this->addChild(armature);

骨骼动画翻转armature->setScaleX(-1);加载到节点上翻转节点没有效果

1.异步加载

CCArmatureDataManager::sharedArmatureDataManager()->addArmaturefileInfoAsync("armature/HeroAnimation.ExportJson",this,schedule_selector(TestAsynchronousLoading::dataLoaded));


2.直接加载

CCArmatureDataManager::sharedArmatureDataManager()->addArmaturefileInfo("armature/bear.ExportJson");

3.移除加载

CCArmatureDataManager::sharedArmatureDataManager()->removeArmaturefileInfo("armature/bear.ExportJson");

4.骨骼动画常用 *** 作

cocos2d::extension::CCArmature *armature = NulL;

armature = cocos2d::extension::CCArmature::create("Dragon");

int num = armature->getAnimation()->getMovementCount(); //得到动作数量

armature->getAnimation()->playWithIndex(0); //动作序号(上面的num)

int index[] = {0,1,2};

std::vector<int> indexes(index,index+3);

armature->getAnimation()->playWithIndexes(indexes); //多动作连续播放

std::string str = armature->getAnimation()->getCurrentMovementID(); //得到当前动作名

armature->getAnimation()->play("Fire",10); //动画名

armature->getAnimation()->setSpeedScale(0.4f); //速度

armature->getAnimation()->setMovementEventCallFunc(this,movementEvent_selector(TestAnimationEvent::animationEvent)); //关联动画事件

armature->setposition(VisibleRect::center().x,VisibleRect::center().y * 0.3f);

armature->setScale(0.6f);

addChild(armature);

cocos2d::extension::CCBone *bone = cocos2d::extension::CCBone::create("p1");

bone->adddisplay(p1,0);

bone->changedisplayWithIndex(0,true);

bone->setIgnoreMovementBoneData(true);

bone->setZOrder(100);

bone->setScale(1.2f);

armature->addBone(bone,"bady-a3");

std::string weapon[] = {"weapon_f-sword.png","weapon_f-sword2.png","weapon_f-sword3.png","weapon_f-sword4.png","weapon_f-sword5.png","weapon_f-knife.png","weapon_f-hammer.png"};

cocos2d::extension::CCSkin *skin = CCSkin::createWithSpriteFramename(weapon[i].c_str());

armature->getBone("weapon")->adddisplay(skin,i); //添加显示

armature->getBone("weapon")->changedisplayWithIndex(displayIndex,true); //替换显示

5.cocos2d::extension::CCBatchNode 批量节点渲染

3.0之前的版本教程

1.异步加载
CCArmatureDataManager::sharedArmatureDataManager()->addArmaturefileInfoAsync("armature/HeroAnimation.ExportJson",schedule_selector(TestAsynchronousLoading::dataLoaded));

2.直接加载
CCArmatureDataManager::sharedArmatureDataManager()->addArmaturefileInfo("armature/bear.ExportJson");
3.移除加载
CCArmatureDataManager::sharedArmatureDataManager()->removeArmaturefileInfo("armature/bear.ExportJson");
4.骨骼动画常用 *** 作
cocos2d::extension::CCArmature*armature=NulL;
armature=cocos2d::extension::CCArmature::create("Dragon");
intnum=armature->getAnimation()->getMovementCount();//得到动作数量
armature->getAnimation()->playWithIndex(0);//动作序号(上面的num)
intindex[]={0,2};
std::vector<int>indexes(index,index+3);
armature->getAnimation()->playWithIndexes(indexes);//多动作连续播放
std::stringstr=armature->getAnimation()->getCurrentMovementID();//得到当前动作名
armature->getAnimation()->play("Fire",10);//动画名
armature->getAnimation()->setSpeedScale(0.4f);//速度
armature->getAnimation()->setMovementEventCallFunc(this,movementEvent_selector(TestAnimationEvent::animationEvent));//关联动画事件
armature->setposition(VisibleRect::center().x,VisibleRect::center().y*0.3f);
armature->setScale(0.6f);
addChild(armature);
cocos2d::extension::CCBone*bone=cocos2d::extension::CCBone::create("p1");
bone->adddisplay(p1,0);
bone->changedisplayWithIndex(0,true);
bone->setIgnoreMovementBoneData(true);
bone->setZOrder(100);
bone->setScale(1.2f);
armature->addBone(bone,"bady-a3");
std::stringweapon[]={"weapon_f-sword.png","weapon_f-hammer.png"};
cocos2d::extension::CCSkin*skin=CCSkin::createWithSpriteFramename(weapon[i].c_str());
armature->getBone("weapon")->adddisplay(skin,i);//添加显示
armature->getBone("weapon")->changedisplayWithIndex(displayIndex,true);//替换显示
5.cocos2d::extension::CCBatchNode批量节点渲染

总结

以上是内存溢出为你收集整理的Cocos2dx v3.2骨骼动画加载学习全部内容,希望文章能够帮你解决Cocos2dx v3.2骨骼动画加载学习所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1002522.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存