mirror of https://github.com/axmolengine/axmol.git
issue #45: fix logic error of insertChild()
This commit is contained in:
parent
2b3e708c5b
commit
b4c8d88707
|
@ -449,25 +449,46 @@ void CCSpriteSheet::insertChild(CCSprite *pobSprite, unsigned int uIndex)
|
||||||
m_pobDescendants->insertObjectAtIndex(pobSprite, uIndex);
|
m_pobDescendants->insertObjectAtIndex(pobSprite, uIndex);
|
||||||
|
|
||||||
// update indices
|
// update indices
|
||||||
unsigned int u = uIndex + 1;
|
unsigned int i = 0;
|
||||||
|
if (m_pobDescendants && m_pobDescendants->count() > 0)
|
||||||
NSMutableArray<CCSprite*>::NSMutableArrayIterator iter;
|
|
||||||
CCSprite *pSprite;
|
|
||||||
for (iter = m_pobDescendants->begin(); iter != m_pobDescendants->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
CCSprite *child = *iter;
|
NSMutableArray<CCSprite*>::NSMutableArrayIterator iter;
|
||||||
child->setAtlasIndex(child->getAtlasIndex() + 1);
|
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
|
// add children recursively
|
||||||
NSMutableArray<CCNode*> *pChildren = pobSprite->getChildren();
|
NSMutableArray<CCNode*> *pChildren = pobSprite->getChildren();
|
||||||
NSMutableArray<CCNode*>::NSMutableArrayIterator iterNode;
|
if (pChildren && pChildren->count() > 0)
|
||||||
for (iterNode = pChildren->begin(); iterNode != pChildren->end(); ++iterNode)
|
|
||||||
{
|
{
|
||||||
pSprite = static_cast<CCSprite*>(*iterNode);
|
NSMutableArray<CCNode*>::NSMutableArrayIterator iterNode;
|
||||||
unsigned int uIndex = atlasIndexForChild(pSprite, pSprite->getZOrder());
|
CCSprite *pSprite;
|
||||||
insertChild(pSprite, uIndex);
|
for (iterNode = pChildren->begin(); iterNode != pChildren->end(); ++iterNode)
|
||||||
|
{
|
||||||
|
pSprite = static_cast<CCSprite*>(*iterNode);
|
||||||
|
|
||||||
|
if (! pSprite)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int uIndex = atlasIndexForChild(pSprite, pSprite->getZOrder());
|
||||||
|
insertChild(pSprite, uIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteSheet::removeSpriteFromAtlas(CCSprite *pobSprite)
|
void CCSpriteSheet::removeSpriteFromAtlas(CCSprite *pobSprite)
|
||||||
|
|
Loading…
Reference in New Issue