void CCDisplayManager::addDisplay(CCNode *display, int index) { CCDecorativeDisplay *decoDisplay = NULL; if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) { decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->objectAtIndex(index); } else { decoDisplay = CCDecorativeDisplay::create(); m_pDecoDisplayList->addObject(decoDisplay); } CCDisplayData *displayData = NULL; if (CCSkin *skin = dynamic_cast<CCSkin *>(display)) { skin->setBone(m_pBone); displayData = CCSpriteDisplayData::create(); CCDisplayFactory::initSpriteDisplay(m_pBone, decoDisplay, skin->getDisplayName().c_str(), skin); if (CCSpriteDisplayData *spriteDisplayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData()) { skin->setSkinData(spriteDisplayData->skinData); } else { CCBaseData baseData; skin->setSkinData(baseData); } } else if (dynamic_cast<CCParticleSystemQuad *>(display)) { displayData = CCParticleDisplayData::create(); } else if(CCArmature *armature = dynamic_cast<CCArmature *>(display)) { displayData = CCArmatureDisplayData::create(); armature->setParentBone(m_pBone); } else { displayData = CCDisplayData::create(); } decoDisplay->setDisplay(display); decoDisplay->setDisplayData(displayData); //! if changed display index is current display index, then change current display to the new display if(index == m_iDisplayIndex) { m_iDisplayIndex = -1; changeDisplayByIndex(index, false); } }
void CCDisplayFactory::updateDisplay(CCBone *bone, float dt, bool dirty) { CCNode *display = bone->getDisplayRenderNode(); CS_RETURN_IF(!display); switch(bone->getDisplayRenderNodeType()) { case CS_DISPLAY_SPRITE: if (dirty) { (static_cast<CCSkin*>(display))->updateArmatureTransform(); } break; case CS_DISPLAY_PARTICLE: updateParticleDisplay(bone, display, dt); break; case CS_DISPLAY_ARMATURE: updateArmatureDisplay(bone, display, dt); break; default: display->setAdditionalTransform(bone->nodeToArmatureTransform()); break; } #if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX if (dirty) { CCDecorativeDisplay *decoDisplay = bone->getDisplayManager()->getCurrentDecorativeDisplay(); CCColliderDetector *detector = decoDisplay->getColliderDetector(); if (detector) { do { #if ENABLE_PHYSICS_BOX2D_DETECT CC_BREAK_IF(!detector->getBody()); #elif ENABLE_PHYSICS_CHIPMUNK_DETECT CC_BREAK_IF(!detector->getBody()); #endif CCAffineTransform displayTransform = display->nodeToParentTransform(); CCPoint anchorPoint = display->getAnchorPointInPoints(); anchorPoint = CCPointApplyAffineTransform(anchorPoint, displayTransform); displayTransform.tx = anchorPoint.x; displayTransform.ty = anchorPoint.y; CCAffineTransform t = CCAffineTransformConcat(displayTransform, bone->getArmature()->nodeToParentTransform()); detector->updateTransform(t); } while (0); } } #endif }
void CCDisplayManager::initDisplayList(CCBoneData *boneData) { CC_SAFE_DELETE(m_pDecoDisplayList); m_pDecoDisplayList = CCArray::create(); m_pDecoDisplayList->retain(); CS_RETURN_IF(!boneData); CCObject *object = NULL; CCArray *displayDataList = &boneData->displayDataList; CCARRAY_FOREACH(displayDataList, object) { CCDisplayData *displayData = (CCDisplayData *)object; CCDecorativeDisplay *decoDisplay = CCDecorativeDisplay::create(); decoDisplay->setDisplayData(displayData); CCDisplayFactory::createDisplay(m_pBone, decoDisplay); m_pDecoDisplayList->addObject(decoDisplay); }
void CCDisplayManager::addDisplay(CCNode *display, int index) { CCDecorativeDisplay *decoDisplay = NULL; if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) { decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->objectAtIndex(index); } else { decoDisplay = CCDecorativeDisplay::create(); m_pDecoDisplayList->addObject(decoDisplay); } CCDisplayData *displayData = NULL; if (CCSkin *skin = dynamic_cast<CCSkin *>(display)) { skin->setBone(m_pBone); displayData = CCSpriteDisplayData::create(); displayData->displayName = skin->getDisplayName(); CCDisplayFactory::initSpriteDisplay(m_pBone, decoDisplay, skin->getDisplayName().c_str(), skin); if (CCSpriteDisplayData *spriteDisplayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData()) { skin->setSkinData(spriteDisplayData->skinData); ((CCSpriteDisplayData *)displayData)->skinData = spriteDisplayData->skinData; } else { bool find = false; for (int i = m_pDecoDisplayList->count()-2; i>=0; i--) { CCDecorativeDisplay *dd = static_cast<CCDecorativeDisplay*>(m_pDecoDisplayList->objectAtIndex(i)); CCSpriteDisplayData *sdd = static_cast<CCSpriteDisplayData *>(dd->getDisplayData()); if (sdd) { find = true; skin->setSkinData(sdd->skinData); (static_cast<CCSpriteDisplayData *>(displayData))->skinData = sdd->skinData; break; } } if (!find) { CCBaseData baseData; skin->setSkinData(baseData); } } } else if (dynamic_cast<CCParticleSystemQuad *>(display)) { displayData = CCParticleDisplayData::create(); display->removeFromParent(); CCArmature *armature = m_pBone->getArmature(); if (armature) { display->setParent(armature); } } else if(CCArmature *armature = dynamic_cast<CCArmature *>(display)) { displayData = CCArmatureDisplayData::create(); displayData->displayName = armature->getName(); armature->setParentBone(m_pBone); } else { displayData = CCDisplayData::create(); } decoDisplay->setDisplay(display); decoDisplay->setDisplayData(displayData); //! if changed display index is current display index, then change current display to the new display if(index == m_iDisplayIndex) { m_iDisplayIndex = -1; changeDisplayWithIndex(index, false); } }