cocos2dx 2.2.1 骨骼动画使用

使用骨骼动画:

    // 加载资源文件 png 图片,plist 文件和 ExportJson 动画文件,一般而言可以在场景运行之初加载此资源

    CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("resTest/Hero/Hero.ExportJson");

   CCArmature* _pArrmature = CCArmature::create("Hero");

    _pArrmature->getAnimation()->play("walk");//设置当前运行动画的索引,一个“工程”可以建立多个动画

     _pArrmature->getAnimation()->setSpeedScale(0.1f);//修改骨骼动画播放速度

    _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("响应事件");
    }
}

2、骨骼动画属性

        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正在播放的帧

3、为骨骼动画的一个骨骼添加粒子效果

    //设置粒子
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"为骨骼动画中骨骼的名称

 

posted @ 2014-07-01 16:31  唯美坏少  阅读(2144)  评论(0编辑  收藏  举报