bool Armature::init(const char *name) { bool bRet = false; do { removeAllChildren(); CC_SAFE_DELETE(_animation); _animation = new ArmatureAnimation(); _animation->init(this); CC_SAFE_DELETE(_boneDic); _boneDic = new Dictionary(); CC_SAFE_DELETE(_topBoneList); _topBoneList = new Array(); _topBoneList->init(); _blendFunc.src = CC_BLEND_SRC; _blendFunc.dst = CC_BLEND_DST; _name = name == NULL ? "" : name; ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance(); if(_name.length() != 0) { _name = name; AnimationData *animationData = armatureDataManager->getAnimationData(name); CCASSERT(animationData, "AnimationData not exist! "); _animation->setAnimationData(animationData); ArmatureData *armatureData = armatureDataManager->getArmatureData(name); CCASSERT(armatureData, ""); _armatureData = armatureData; DictElement *_element = NULL; Dictionary *boneDataDic = &armatureData->boneDataDic; CCDICT_FOREACH(boneDataDic, _element) { Bone *bone = createBone(_element->getStrKey()); //! init bone's Tween to 1st movement's 1st frame do { MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str()); CC_BREAK_IF(!movData); MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str()); CC_BREAK_IF(!movBoneData || movBoneData->frameList.count() <= 0); FrameData *frameData = movBoneData->getFrameData(0); CC_BREAK_IF(!frameData); bone->getTweenData()->copy(frameData); bone->changeDisplayByIndex(frameData->displayIndex, false); } while (0); } update(0); updateOffsetPoint(); }
bool Armature::init(const char *name) { bool bRet = false; do { //cocos2d::CCLog("Armature (%s) create.", name); removeAllChildren(); CC_SAFE_DELETE(m_pAnimation); m_pAnimation = new Animation(); m_pAnimation->init(this); CC_SAFE_DELETE(m_pBoneDic); m_pBoneDic = new CCDictionary(); CC_SAFE_DELETE(m_pTopBoneList); m_pTopBoneList = new CCArray(); m_pTopBoneList->init(); m_sBlendFunc.src = CC_BLEND_SRC; m_sBlendFunc.dst = CC_BLEND_DST; m_strName = name == NULL ? "" : name; ArmatureDataManager *armatureDataManager = ArmatureDataManager::sharedArmatureDataManager(); if(m_strName.compare("") != 0) { m_strName = name; AnimationData* animationData = armatureDataManager->getAnimationData(name); CCAssert(animationData, "AnimationData not exist! "); m_pAnimation->setAnimationData(animationData); ArmatureData *armatureData = armatureDataManager->getArmatureData(name); CCAssert(armatureData, ""); m_pArmatureData = armatureData; CCDictElement *_element = NULL; CCDictionary *boneDataDic = &armatureData->boneDataDic; CCDICT_FOREACH(boneDataDic, _element) { Bone *bone = createBone(_element->getStrKey()); //! init bone's Tween to 1st movement's 1st frame do { MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str()); CC_BREAK_IF(!movData); MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str()); CC_BREAK_IF(!movBoneData || movBoneData->frameList.count() <= 0); FrameData *frameData = movBoneData->getFrameData(0); CC_BREAK_IF(!frameData); bone->getTweenData()->copy(frameData); bone->changeDisplayByIndex(frameData->displayIndex, false); } while (0); } update(0); updateOffsetPoint(); }
bool Armature::init(const std::string& name) { bool bRet = false; do { removeAllChildren(); CC_SAFE_DELETE(_animation); _animation = new ArmatureAnimation(); _animation->init(this); _boneDic.clear(); _topBoneList.clear(); _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; _name = name; ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance(); if(!_name.empty()) { AnimationData *animationData = armatureDataManager->getAnimationData(name); CCASSERT(animationData, "AnimationData not exist! "); _animation->setAnimationData(animationData); ArmatureData *armatureData = armatureDataManager->getArmatureData(name); CCASSERT(armatureData, ""); _armatureData = armatureData; for (auto& element : armatureData->boneDataDic) { Bone *bone = createBone(element.first.c_str()); //! init bone's Tween to 1st movement's 1st frame do { MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str()); CC_BREAK_IF(!movData); MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str()); CC_BREAK_IF(!movBoneData || movBoneData->frameList.size() <= 0); FrameData *frameData = movBoneData->getFrameData(0); CC_BREAK_IF(!frameData); bone->getTweenData()->copy(frameData); bone->changeDisplayWithIndex(frameData->displayIndex, false); } while (0); } update(0); updateOffsetPoint(); } else { _name = "new_armature"; _armatureData = ArmatureData::create(); _armatureData->name = _name; AnimationData *animationData = AnimationData::create(); animationData->name = _name; armatureDataManager->addArmatureData(_name.c_str(), _armatureData); armatureDataManager->addAnimationData(_name.c_str(), animationData); _animation->setAnimationData(animationData); } setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); setCascadeOpacityEnabled(true); setCascadeColorEnabled(true); bRet = true; } while (0); return bRet; }
bool Armature::init(const char *name) { bool bRet = false; do { //cocos2d::CCLog("Armature (%s) create.", name); CC_SAFE_DELETE(m_pAnimation); m_pAnimation = Animation::create(this); CCAssert(m_pAnimation, "create Armature::m_pAnimation fail!"); m_pAnimation->retain(); CC_SAFE_DELETE(m_pBoneDic); m_pBoneDic = CCDictionary::create(); CCAssert(m_pBoneDic, "create Armature::m_pBoneDic fail!"); m_pBoneDic->retain(); m_sBlendFunc.src = CC_BLEND_SRC; m_sBlendFunc.dst = CC_BLEND_DST; m_strName = name == NULL ? "" : name; ArmatureDataManager *armatureDataManager = ArmatureDataManager::sharedArmatureDataManager(); if(m_strName.compare("") != 0) { m_strName = name; AnimationData* animationData = armatureDataManager->getAnimationData(name); CCAssert(animationData, "AnimationData not exist! "); m_pAnimation->setAnimationData(animationData); ArmatureData *armatureData = armatureDataManager->getArmatureData(name); CCAssert(armatureData, ""); m_pArmatureData = armatureData; CCDictElement *_element = NULL; CCDictionary *boneDataDic = &armatureData->boneDataDic; CCDICT_FOREACH(boneDataDic, _element) { Bone *bone = createBone(_element->getStrKey()); //! init bone's Tween to 1st movement's 1st frame do { MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str()); CC_BREAK_IF(!movData); MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str()); CC_BREAK_IF(!movBoneData || movBoneData->frameList.count() <= 0); FrameData *_frameData = movBoneData->getFrameData(0); CC_BREAK_IF(!_frameData); bone->getTweenData()->copy(_frameData); } while (0); } }