// Reorder will be done in this function, no "lazy" reorder to particles void CCParticleBatchNode::reorderChild(CCNode * child, int zOrder) { CCAssert( child != NULL, "Child must be non-NULL"); CCAssert( dynamic_cast<CCParticleSystem*>(child) != NULL, "CCParticleBatchNode only supports CCQuadParticleSystems as children"); CCAssert( m_pChildren->containsObject(child), "Child doesn't belong to batch" ); CCParticleSystem* pChild = (CCParticleSystem*)(child); if( zOrder == child->getZOrder() ) { return; } // no reordering if only 1 child if( m_pChildren->count() > 1) { unsigned int newIndex = 0, oldIndex = 0; getCurrentIndex(&oldIndex, &newIndex, pChild, zOrder); if( oldIndex != newIndex ) { // reorder m_pChildren->array pChild->retain(); m_pChildren->removeObjectAtIndex(oldIndex); m_pChildren->insertObject(pChild, newIndex); pChild->release(); // save old altasIndex unsigned int oldAtlasIndex = pChild->getAtlasIndex(); // update atlas index updateAllAtlasIndexes(); // Find new AtlasIndex unsigned int newAtlasIndex = 0; for( unsigned int i=0;i < m_pChildren->count();i++) { CCParticleSystem* pNode = (CCParticleSystem*)m_pChildren->objectAtIndex(i); if( pNode == pChild ) { newAtlasIndex = pChild->getAtlasIndex(); break; } } // reorder textureAtlas quads m_pTextureAtlas->moveQuadsFromIndex(oldAtlasIndex, pChild->getTotalParticles(), newAtlasIndex); pChild->updateWithNoTime(); } } pChild->setZOrderValue(zOrder); }