mirror of https://github.com/axmolengine/axmol.git
add functions:
void CCSpriteBatchNode::addQuadFromSprite(CCSprite *sprite, unsigned int index); CCSpriteBatchNode * CCSpriteBatchNode::addSpriteWithoutQuad(CCSprite*child, unsigned int z, int aTag);
This commit is contained in:
parent
05bf58b488
commit
35d611155b
|
@ -163,6 +163,21 @@ namespace cocos2d
|
||||||
virtual void removeAllChildrenWithCleanup(bool cleanup);
|
virtual void removeAllChildrenWithCleanup(bool cleanup);
|
||||||
virtual void draw(void);
|
virtual void draw(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* IMPORTANT XXX IMPORTNAT:
|
||||||
|
* These 2 methods can't be part of CCTMXLayer since they call [super add...], and CCSpriteSheet#add SHALL not be called
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Adds a quad into the texture atlas but it won't be added into the children array.
|
||||||
|
This method should be called only when you are dealing with very big AtlasSrite and when most of the CCSprite won't be updated.
|
||||||
|
For example: a tile map (CCTMXMap) or a label with lots of characters (BitmapFontAtlas)
|
||||||
|
*/
|
||||||
|
void addQuadFromSprite(CCSprite *sprite, unsigned int index);
|
||||||
|
/* This is the opposite of "addQuadFromSprite.
|
||||||
|
It add the sprite to the children and descendants array, but it doesn't update add it to the texture atlas
|
||||||
|
*/
|
||||||
|
CCSpriteBatchNode * addSpriteWithoutQuad(CCSprite*child, unsigned int z, int aTag);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateBlendFunc();
|
void updateBlendFunc();
|
||||||
|
|
||||||
|
|
|
@ -625,4 +625,62 @@ namespace cocos2d
|
||||||
updateBlendFunc();
|
updateBlendFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CCSpriteSheet Extension
|
||||||
|
//implementation CCSpriteSheet (TMXTiledMapExtension)
|
||||||
|
|
||||||
|
void CCSpriteBatchNode::addQuadFromSprite(CCSprite *sprite, unsigned int index)
|
||||||
|
{
|
||||||
|
NSAssert( sprite != NULL, "Argument must be non-nil");
|
||||||
|
/// @todo NSAssert( [sprite isKindOfClass:[CCSprite class]], @"CCSpriteSheet only supports CCSprites as children");
|
||||||
|
|
||||||
|
while(index >= m_pobTextureAtlas->getCapacity() || m_pobTextureAtlas->getCapacity() == m_pobTextureAtlas->getTotalQuads())
|
||||||
|
{
|
||||||
|
this->increaseAtlasCapacity();
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// update the quad directly. Don't add the sprite to the scene graph
|
||||||
|
//
|
||||||
|
sprite->useBatchNode(this);
|
||||||
|
sprite->setAtlasIndex(index);
|
||||||
|
|
||||||
|
ccV3F_C4B_T2F_Quad quad = sprite->getQuad();
|
||||||
|
m_pobTextureAtlas->insertQuad(&quad, index);
|
||||||
|
|
||||||
|
// XXX: updateTransform will update the textureAtlas too using updateQuad.
|
||||||
|
// XXX: so, it should be AFTER the insertQuad
|
||||||
|
sprite->setDirty(YES);
|
||||||
|
sprite->updateTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
CCSpriteBatchNode * CCSpriteBatchNode::addSpriteWithoutQuad(CCSprite*child, unsigned int z, int aTag)
|
||||||
|
{
|
||||||
|
NSAssert( child != NULL, "Argument must be non-nil");
|
||||||
|
/// @todo NSAssert( [child isKindOfClass:[CCSprite class]], @"CCSpriteSheet only supports CCSprites as children");
|
||||||
|
|
||||||
|
// quad index is Z
|
||||||
|
child->setAtlasIndex(z);
|
||||||
|
|
||||||
|
// XXX: optimize with a binary search
|
||||||
|
int i=0;
|
||||||
|
if (m_pobDescendants && m_pobDescendants->count() > 0)
|
||||||
|
{
|
||||||
|
NSMutableArray<CCSprite*>::NSMutableArrayIterator iter;
|
||||||
|
for (iter = m_pobDescendants->begin(); iter != m_pobDescendants->end(); ++iter)
|
||||||
|
{
|
||||||
|
// fast dispatch
|
||||||
|
if (!(*iter) || (*iter)->getAtlasIndex() >=z)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_pobDescendants->insertObjectAtIndex(child, i);
|
||||||
|
|
||||||
|
// IMPORTANT: Call super, and not self. Avoid adding it to the texture atlas array
|
||||||
|
CCNode::addChild(child, z, aTag);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue