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

一、使用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 批量节点渲染

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...