zoukankan      html  css  js  c++  java
  • 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"为骨骼动画中骨骼的名称
  • 相关阅读:
    Codeforces Round #344 (Div. 2) C. Report 其他
    Codeforces Round #344 (Div. 2) B. Print Check 水题
    Codeforces Round #344 (Div. 2) A. Interview 水题
    8VC Venture Cup 2016
    CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂 中二版
    CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂
    CDOJ 1279 班委选举 每周一题 div2 暴力
    每周算法讲堂 快速幂
    8VC Venture Cup 2016
    Educational Codeforces Round 9 F. Magic Matrix 最小生成树
  • 原文地址:https://www.cnblogs.com/android-qian/p/3818633.html
Copyright © 2011-2022 走看看