使用骨骼动画:函数
// 加载资源文件 png 图片,plist 文件和 ExportJson 动画文件,通常而言能够在场景运行之初加载此资源动画
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("resTest/Hero/Hero.ExportJson");this
CCArmature* _pArrmature = CCArmature::create("Hero");spa
_pArrmature->getAnimation()->play("walk");//设置当前运行动画的索引,一个“工程”能够创建多个动画code
_pArrmature->getAnimation()->setSpeedScale(0.1f);//修改骨骼动画播放速度blog
_pArrmature->getAnimation()->setFrameEventCallFunc(this,frameEvent_selector(LoadingGongShiLayer::onFrameEvent));//添加骨骼动画关键帧回调函数索引
_pArrmature->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(LoadingGongShiLayer::animationEvent));//添加骨骼动画动做事件回调函数事件
this->addChild(_pArrmature);图片
//播放完触发事件 void LoadingGongShiLayer::animationEvent(CCArmature *armature, MovementEventType movementType, const char *movementID){ std::string id = movementID; CCSize size = CCDirector::sharedDirector()->getWinSize(); if (movementType == LOOP_COMPLETE) { if (id.compare("walk") == 0) { CCLOG("骨骼动画行走结束"); } } }
//关键帧
void LoadingGongShiLayer::onFrameEvent(Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex) { if(strcmp(evt,"100") == 0) { CCLOG("响应事件");
} }
二、骨骼动画属性资源
string a = _pArrmature->getAnimation()->getCurrentMovementID();//获取当前播放的动画
int q = _pArrmature->getAnimation()->getCurrentFrameIndex();//获取当前帧
CCArmature *m_pArmature = CCArmature::create(_pArrmature->getName().c_str());//建立一个新的骨骼动画2
m_pArmature->getAnimation()->play(a.c_str());//骨骼动画2播放骨骼动画1正在播放的动做
m_pArmature->getAnimation()->gotoAndPlay(q);//骨骼动画2播放骨骼动画1正在播放的帧
三、为骨骼动画的一个骨骼添加粒子效果
//设置粒子
CCParticleSystem *p1 = CCParticleSystemQuad::create("resParticles/DR_gongji_bingjian_hd.plist"); //建立一个骨骼 CCBone *bone = cocos2d::extension::CCBone::create("p1"); //在新骨骼上面添加粒子效果 bone->addDisplay(p1, 0); bone->changeDisplayByIndex(0, true); bone->setIgnoreMovementBoneData(true); bone->setZOrder(100); bone->setScale(1.2f); _pArrmature->addBone(bone, "wuqi");//"wuqi"为骨骼动画中骨骼的名称