This commit is contained in:
Ming 2010-08-13 03:18:31 +00:00
parent 5448bdd392
commit 1f2117fb19
1 changed files with 77 additions and 30 deletions

View File

@ -226,13 +226,22 @@ void CCSpriteSheet::removeChildAtIndex(unsigned int uIndex, bool bDoCleanup)
void CCSpriteSheet::removeAllChildrenWithCleanup(bool bCleanup)
{
// Invalidate atlas index. issue #569
if (m_pChildren && m_pChildren->count() > 0)
{
CCSprite *pSprite;
NSMutableArray<CCNode*>::NSMutableArrayIterator iter;
for (iter = m_pChildren->begin(); iter != m_pChildren->end(); ++iter)
{
pSprite = static_cast<CCSprite*>(*iter);
if (! pSprite)
{
break;
}
pSprite->useSelfRender();
}
}
__super::removeAllChildrenWithCleanup(bCleanup);
@ -256,6 +265,11 @@ void CCSpriteSheet::draw(void)
{
pSprite = *iter;
if (! pSprite)
{
break;
}
// fast dispatch
if (pSprite->isDirty())
{
@ -312,17 +326,27 @@ void CCSpriteSheet::increaseAtlasCapacity(void)
unsigned int CCSpriteSheet::rebuildIndexInOrder(CCSprite *pobParent, unsigned int uIndex)
{
CCSprite *pSprite;
NSMutableArray<CCNode*> *pChildren = pobParent->getChildren();
if (pChildren && pChildren->count() > 0)
{
CCSprite *pSprite;
NSMutableArray<CCNode*>::NSMutableArrayIterator iter;
for (iter = pChildren->begin(); iter != pChildren->end(); ++iter)
{
pSprite = static_cast<CCSprite*>(*iter);
if (! pSprite)
{
break;
}
if (pSprite->getZOrder() < 0)
{
uIndex = rebuildIndexInOrder(pSprite, uIndex);
}
}
}
// ignore self (spritesheet)
if (! pobParent->isEqual(this))
@ -331,14 +355,25 @@ unsigned int CCSpriteSheet::rebuildIndexInOrder(CCSprite *pobParent, unsigned in
uIndex++;
}
if (pChildren && pChildren->count() > 0)
{
CCSprite *pSprite;
NSMutableArray<CCNode*>::NSMutableArrayIterator iter;
for (iter = pChildren->begin(); iter != pChildren->end(); ++iter)
{
pSprite = static_cast<CCSprite*>(*iter);
if (! pSprite)
{
break;
}
if (pSprite->getZOrder() >= 0)
{
uIndex = rebuildIndexInOrder(pSprite, uIndex);
}
}
}
return uIndex;
}
@ -346,8 +381,8 @@ unsigned int CCSpriteSheet::rebuildIndexInOrder(CCSprite *pobParent, unsigned in
unsigned int CCSpriteSheet::highestAtlasIndexInChild(CCSprite *pSprite)
{
NSMutableArray<CCNode*> *pChildren = pSprite->getChildren();
int count = pChildren->count();
if (count == 0)
if (! pChildren || pChildren->count() == 0)
{
return pSprite->getAtlasIndex();
}
@ -360,8 +395,8 @@ unsigned int CCSpriteSheet::highestAtlasIndexInChild(CCSprite *pSprite)
unsigned int CCSpriteSheet::lowestAtlasIndexInChild(CCSprite *pSprite)
{
NSMutableArray<CCNode*> *pChildren = pSprite->getChildren();
int count = pChildren->count();
if (count == 0)
if (! pChildren || pChildren->count() == 0)
{
return pSprite->getAtlasIndex();
}
@ -505,22 +540,34 @@ void CCSpriteSheet::removeSpriteFromAtlas(CCSprite *pobSprite)
m_pobDescendants->removeObjectAtIndex(uIndex);
// update all sprites beyond this one
NSMutableArray<CCSprite*>::NSMutableArrayIterator iter;
for (iter = m_pobDescendants->begin(); iter != m_pobDescendants->end(); ++iter)
unsigned int count = m_pobDescendants->count();
for(; uIndex < count; ++uIndex)
{
(*iter)->setAtlasIndex((*iter)->getAtlasIndex() - 1);
CCSprite* s = static_cast<CCSprite*>(m_pobDescendants->getObjectAtIndex(uIndex));
s->setAtlasIndex( s->getAtlasIndex() - 1 );
}
}
// remove children recursively
NSMutableArray<CCNode*> *pChildren = pobSprite->getChildren();
if (pChildren && pChildren->count() > 0)
{
CCSprite *pSprite;
NSMutableArray<CCNode*>::NSMutableArrayIterator iter;
for (iter = pChildren->begin(); iter != pChildren->end(); ++iter)
{
pSprite = static_cast<CCSprite*>(*iter);
if (! pSprite)
{
break;
}
removeSpriteFromAtlas(pSprite);
}
}
}
void CCSpriteSheet::updateBlendFunc(void)