加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 19:03:00 所属栏目:百科 来源:网络整理
导读:一、使用 Cocos Studio之前需要导入GUI、Extensions、CocosStudio的类库 右击解决方案选择添加现有项目添加这三个库文件导入成功效果如下 二、选择工程右键选择 属性-》通用属性-》添加新引用 勾选所添加库的lib选项效果图如下,完成后效果如下 三、添加附加

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

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

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

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


三、添加附加包含目录

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

在附加包含目录中添加

$(EngineRoot) extensions需要

$(EngineRoot)cocoseditor-support cocosStudio需要

$(EngineRoot)cocoseditor-supportcocostudio 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批量节点渲染

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读