void TestParticleDisplay::onEnter() { ArmatureTestLayer::onEnter(); auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesEnded = CC_CALLBACK_2(TestParticleDisplay::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); animationID = 0; armature = Armature::create("robot"); armature->getAnimation()->playWithIndex(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->changeDisplayWithIndex(0, true); bone->setIgnoreMovementBoneData(true); bone->setLocalZOrder(100); bone->setScale(1.2f); armature->addBone(bone, "bady-a3"); bone = Bone::create("p2"); bone->addDisplay(p2, 0); bone->changeDisplayWithIndex(0, true); bone->setIgnoreMovementBoneData(true); bone->setLocalZOrder(100); bone->setScale(1.2f); armature->addBone(bone, "bady-a30"); }
void Hero::changeMount(Armature *armature) { if (armature == nullptr) { retain(); playWithIndex(0); //Remove hero from display list m_pMount->getBone("hero")->removeDisplay(0); m_pMount->stopAllActions(); //Set position to current position setPosition(m_pMount->getPosition()); //Add to layer m_pLayer->addChild(this); release(); setMount(armature); } else { setMount(armature); retain(); //Remove from layer removeFromParentAndCleanup(false); //Get the hero bone Bone *bone = armature->getBone("hero"); //Add hero as a display to this bone bone->addDisplay(this, 0); //Change this bone's display bone->changeDisplayWithIndex(0, true); bone->setIgnoreMovementBoneData(true); setPosition(Vec2(0,0)); //Change animation playWithIndex(1); setScale(1); release(); } }
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; }