MCPcopy Create free account
hub / github.com/axmolengine/axmol / appendChild

Method appendChild

core/2d/SpriteBatchNode.cpp:592–634  ·  view source on GitHub ↗

addChild helper, faster than insertChild

Source from the content-addressed store, hash-verified

590
591// addChild helper, faster than insertChild
592void SpriteBatchNode::appendChild(Sprite* sprite)
593{
594 _reorderChildDirty = true;
595 sprite->setBatchNode(this);
596 sprite->setDirty(true);
597
598 if (_textureAtlas->getTotalQuads() == _textureAtlas->getCapacity())
599 {
600 increaseAtlasCapacity();
601 }
602
603 _descendants.emplace_back(sprite);
604 int index = static_cast<int>(_descendants.size() - 1);
605
606 sprite->setAtlasIndex(index);
607
608 auto&& quad = sprite->getQuad();
609 _textureAtlas->insertQuad(quad, index);
610
611 // add children recursively
612 auto& children = sprite->getChildren();
613
614 // axmol Github issue #502
615 for (auto iter = children.begin(); iter != children.end();)
616 {
617 auto child = *iter;
618#if AX_SPRITE_DEBUG_DRAW
619 // when using AX_SPRITE_DEBUG_DRAW, a DrawNode is appended to sprites. remove it since only Sprites can be used
620 // as children in SpriteBatchNode
621 // Github issue #14730
622 if (dynamic_cast<DrawNode*>(child))
623 {
624 sprite->resetChild(child, true);
625 iter = children.erase(iter);
626 continue;
627 }
628#endif
629 AXASSERT(dynamic_cast<Sprite*>(child) != nullptr,
630 "You can only add Sprites (or subclass of Sprite) to SpriteBatchNode");
631 appendChild(static_cast<Sprite*>(child));
632 ++iter;
633 }
634}
635
636void SpriteBatchNode::removeSpriteFromAtlas(Sprite* sprite)
637{

Callers 2

addChildMethod · 0.80
hacks.jsFile · 0.80

Calls 11

setDirtyMethod · 0.80
getTotalQuadsMethod · 0.80
insertQuadMethod · 0.80
resetChildMethod · 0.80
setBatchNodeMethod · 0.45
getCapacityMethod · 0.45
emplace_backMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected