Exemple #1
0
ssize_t SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
{
    auto& siblings = sprite->getParent()->getChildren();
    auto childIndex = siblings.getIndex(sprite);

    // ignore parent Z if parent is spriteSheet
    bool ignoreParent = (SpriteBatchNode*)(sprite->getParent()) == this;
    Sprite *prev = nullptr;
    if (childIndex > 0 && childIndex != -1)
    {
        prev = static_cast<Sprite*>(siblings.at(childIndex - 1));
    }

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

        return highestAtlasIndexInChild(prev) + 1;
    }

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

    // first child of an Sprite ?
    if (childIndex == 0)
    {
        Sprite *p = static_cast<Sprite*>(sprite->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 ((prev->getLocalZOrder() < 0 && nZ < 0) || (prev->getLocalZOrder() >= 0 && nZ >= 0))
        {
            return highestAtlasIndexInChild(prev) + 1;
        }

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

    // Should not happen. Error calculating Z on SpriteSheet
    CCASSERT(0, "should not run here");
    return 0;
}
	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;
	}
Exemple #3
0
ssize_t SpriteBatchNode::highestAtlasIndexInChild(Sprite *sprite)
{
    auto& children = sprite->getChildren();

    if (children.size() == 0)
    {
        return sprite->getAtlasIndex();
    }
    else
    {
        return highestAtlasIndexInChild( static_cast<Sprite*>(children.back()));
    }
}
	unsigned int CCSpriteBatchNode::highestAtlasIndexInChild(CCSprite *pSprite)
	{
		NSMutableArray<CCNode*> *pChildren = pSprite->getChildren();

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