Ejemplo n.º 1
0
void CABatchView::appendSubview(CAView* subview)
{
    m_bReorderChildDirty=true;
    subview->setBatch(this);
    subview->setDirty(true);

    if(m_pobImageAtlas->getTotalQuads() == m_pobImageAtlas->getCapacity()) {
        increaseAtlasCapacity();
    }

    m_obDescendants.pushBack(subview);
    
    unsigned int index = (unsigned int)m_obDescendants.size() - 1;

    subview->setAtlasIndex(index);

    ccV3F_C4B_T2F_Quad quad = subview->getQuad();
    m_pobImageAtlas->insertQuad(&quad, index);
    
    CAVector<CAView*>::const_iterator itr;
    for (itr=subview->getSubviews().begin(); itr!=subview->getSubviews().end(); itr++)
    {
        appendSubview(*itr);
    }
}
Ejemplo n.º 2
0
void CABatchView::insertSubview(CAView *subview, unsigned int uIndex)
{
    subview->setBatch(this);
    subview->setAtlasIndex(uIndex);
    subview->setDirty(true);

    if(m_pobImageAtlas->getTotalQuads() == m_pobImageAtlas->getCapacity())
    {
        increaseAtlasCapacity();
    }

    ccV3F_C4B_T2F_Quad quad = subview->getQuad();
    m_pobImageAtlas->insertQuad(&quad, uIndex);
    m_obDescendants.insert(uIndex, subview);

    
    if (m_obDescendants.size() > uIndex + 1)
    {
        for (CAVector<CAView*>::const_iterator itr=m_obDescendants.begin() + uIndex + 1;
             itr!=m_obDescendants.end();
             itr++)
        {
            (*itr)->setAtlasIndex(subview->getAtlasIndex() + 1);
        }
    }

    for (CAVector<CAView*>::const_iterator itr=subview->getSubviews().begin();
         itr!=subview->getSubviews().end();
         itr++)
    {
        unsigned int idx = atlasIndexForSubview(*itr, (*itr)->getZOrder());
        insertSubview(*itr, idx);
    }
}
Ejemplo n.º 3
0
	void CCSpriteBatchNode::insertChild(CCSprite *pobSprite, unsigned int uIndex)
	{
		pobSprite->useBatchNode(this);
		pobSprite->setAtlasIndex(uIndex);
		pobSprite->setDirty(true);

		if (m_pobTextureAtlas->getTotalQuads() == m_pobTextureAtlas->getCapacity())
		{
			increaseAtlasCapacity();
		}

		ccV3F_C4B_T2F_Quad quad = pobSprite->getQuad();
		m_pobTextureAtlas->insertQuad(&quad, uIndex);

		m_pobDescendants->insertObjectAtIndex(pobSprite, uIndex);

		// update indices
		unsigned int i = 0;
		if (m_pobDescendants && m_pobDescendants->count() > 0)
		{
			NSMutableArray<CCSprite*>::NSMutableArrayIterator iter;
			for (iter = m_pobDescendants->begin(); iter != m_pobDescendants->end(); ++iter)
			{
				if (! *iter)
				{
					break;
				}

				if (i > uIndex)
				{
					(*iter)->setAtlasIndex((*iter)->getAtlasIndex() + 1);
				}

				++i;
			}
		}	

		// add children recursively
		NSMutableArray<CCNode*> *pChildren = pobSprite->getChildren();
		if (pChildren && pChildren->count() > 0)
		{
			NSMutableArray<CCNode*>::NSMutableArrayIterator iterNode;
			CCSprite *pSprite;
			for (iterNode = pChildren->begin(); iterNode != pChildren->end(); ++iterNode)
			{
				pSprite = (CCSprite*)(*iterNode);

				if (! pSprite)
				{
					break;
				}

				unsigned int uIndex = atlasIndexForChild(pSprite, pSprite->getZOrder());
				insertChild(pSprite, uIndex);
			}
		}
	}
Ejemplo n.º 4
0
// addChild helper, faster than insertChild
void SpriteBatchNode::appendChild(Sprite* sprite)
{
    _reorderChildDirty=true;
    sprite->setBatchNode(this);
    sprite->setDirty(true);

    if(_textureAtlas->getTotalQuads() == _textureAtlas->getCapacity()) {
        increaseAtlasCapacity();
    }

    _descendants.push_back(sprite);
    int index = static_cast<int>(_descendants.size()-1);

    sprite->setAtlasIndex(index);

    V3F_C4B_T2F_Quad quad = sprite->getQuad();
    _textureAtlas->insertQuad(&quad, index);

    // add children recursively
    auto& children = sprite->getChildren();
    for(const auto &child: children) {
        appendChild(static_cast<Sprite*>(child));
    }
}