public void insertChild(CCSprite pobSprite, int uIndex) { pobSprite.useBatchNode(this); pobSprite.atlasIndex = uIndex; pobSprite.dirty = true; if (m_pobTextureAtlas.TotalQuads == m_pobTextureAtlas.Capacity) { increaseAtlasCapacity(); } ccV3F_C4B_T2F_Quad quad = pobSprite.quad; m_pobTextureAtlas.insertQuad(quad, uIndex); m_pobDescendants.Insert(uIndex, pobSprite); // update indices uint i = 0; if (m_pobDescendants != null && m_pobDescendants.Count > 0) { for (int j = 0; j < m_pobDescendants.Count; j++) { CCObject pObject = m_pobDescendants[j]; CCSprite pChild = pObject as CCSprite; if (pChild != null) { if (i > uIndex) { pChild.atlasIndex = pChild.atlasIndex + 1; } ++i; } } } // add children recursively List <Node> pChildren = pobSprite.Children; if (pChildren != null && pChildren.Count > 0) { for (int j = 0; j < pChildren.Count; j++) { CCObject pObject = pChildren[j]; CCSprite pChild = pObject as CCSprite; if (pChild != null) { uIndex = atlasIndexForChild(pChild, pChild.ZOrder); insertChild(pChild, uIndex); } } } }