unsigned int CCSpriteBatchNode::atlasIndexForChild(CCSprite *pobSprite, int nZ)
	{
		NSMutableArray<CCNode*> *pBrothers = pobSprite->getParent()->getChildren();
		unsigned int uChildIndex = pBrothers->getIndexOfObject(pobSprite);

		// ignore parent Z if parent is spriteSheet
		bool bIgnoreParent = (CCSpriteBatchNode*)(pobSprite->getParent()) == this;
		CCSprite *pPrevious = NULL;
		if (uChildIndex > 0)
		{
			pPrevious = (CCSprite*)(pBrothers->getObjectAtIndex(uChildIndex - 1));
		}

		// first child of the sprite sheet
		if (bIgnoreParent)
		{
			if (uChildIndex == 0)
			{
				return 0;
			}

			return highestAtlasIndexInChild(pPrevious) + 1;
		}

		// parent is a CCSprite, so, it must be taken into account

		// first child of an CCSprite ?
		if (uChildIndex == 0)
		{
			CCSprite *p = (CCSprite*)(pobSprite->getParent());

			// less than parent and brothers
			if (nZ < 0)
			{
				return p->getAtlasIndex();
			}
			else
			{
				return p->getAtlasIndex() + 1;
			}
		}
		else
		{
			// previous & sprite belong to the same branch
			if ((pPrevious->getZOrder() < 0 && nZ < 0) || (pPrevious->getZOrder() >= 0 && nZ >= 0))
			{
				return highestAtlasIndexInChild(pPrevious) + 1;
			}

			// else (previous < 0 and sprite >= 0 )
			CCSprite *p = (CCSprite*)(pobSprite->getParent());
			return p->getAtlasIndex() + 1;
		}

		// Should not happen. Error calculating Z on SpriteSheet
		assert(0);
		return 0;
	}
void CCAnimate::update(cocos2d::ccTime time)
{
	NSMutableArray<CCSpriteFrame*> *pFrames = m_pAnimation->getFrames();
	unsigned int numberOfFrames = pFrames->count();

	unsigned int idx = (unsigned int)(time * numberOfFrames);

	if (idx >= numberOfFrames)
	{
		idx = numberOfFrames - 1;
	}

	CCSprite *pSprite = (CCSprite*)(m_pTarget);
	if (! pSprite->isFrameDisplayed(pFrames->getObjectAtIndex(idx)))
	{
		pSprite->setDisplayFrame(pFrames->getObjectAtIndex(idx));
	}
}
	unsigned int CCSpriteBatchNode::lowestAtlasIndexInChild(CCSprite *pSprite)
	{
		NSMutableArray<CCNode*> *pChildren = pSprite->getChildren();

		if (! pChildren || pChildren->count() == 0)
		{
			return pSprite->getAtlasIndex();
		}
		else
		{
			return lowestAtlasIndexInChild((CCSprite*)(pChildren->getObjectAtIndex(0)));
		}
	}