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"为骨骼动画中骨骼的名称
  • 相关阅读:
    Vue大文件上传 vuesimpleloader分片上传到AWS S3
    如何把设备安全的接入AWS IoT(一)
    Vue大文件分片上传 直连AWS S3
    JAVA AWS 根据Dynamodb增删改查数据
    JAVA实现和AWS IOT订阅、发布MQTT消息
    AWS 使用总结及部分服务学习记录
    Vue 刷新组件
    Vue文件上传 自定义样式 Button按钮代替Input 并通过java上传(非分片)到AWS S3
    sql 去年,月
    json2【转】
  • 原文地址:https://www.cnblogs.com/android-qian/p/3818633.html
Copyright © 2011-2022 走看看