void TestParticleDisplay::onEnter() { ArmatureTestLayer::onEnter(); setTouchEnabled(true); animationID = 0; armature = Armature::create("robot"); armature->getAnimation()->playByIndex(0); armature->setPosition(VisibleRect::center()); armature->setScale(0.48f); armature->getAnimation()->setSpeedScale(0.5f); addChild(armature); ParticleSystem *p1 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); ParticleSystem *p2 = CCParticleSystemQuad::create("Particles/SmallSun.plist"); Bone *bone = Bone::create("p1"); bone->addDisplay(p1, 0); bone->changeDisplayByIndex(0, true); bone->setIgnoreMovementBoneData(true); bone->setZOrder(100); bone->setScale(1.2f); armature->addBone(bone, "bady-a3"); bone = Bone::create("p2"); bone->addDisplay(p2, 0); bone->changeDisplayByIndex(0, true); bone->setIgnoreMovementBoneData(true); bone->setZOrder(100); bone->setScale(1.2f); armature->addBone(bone, "bady-a30"); }
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(); }