addChild helper, faster than insertChild
| 590 | |
| 591 | // addChild helper, faster than insertChild |
| 592 | void 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 | |
| 636 | void SpriteBatchNode::removeSpriteFromAtlas(Sprite* sprite) |
| 637 | { |
no test coverage detected