change CCNode::insertBefore behaviour to insert at the start if nullptr

This commit is contained in:
HJfod 2023-02-23 22:03:20 +02:00
parent 295aedbdb5
commit 4613af6791
2 changed files with 5 additions and 2 deletions

View file

@ -884,7 +884,7 @@ public:
* @param child The node to add. The node may not be a child of another
* node already
* @param before The child the node is added before of. If this is null or
* not a child of this node, the new child will be placed at the end of the
* not a child of this node, the new child will be placed at the start of the
* child list
*/
GEODE_DLL void insertBefore(CCNode* child, CCNode* before);

View file

@ -17,7 +17,10 @@ void CCNode::swapChildIndices(CCNode* first, CCNode* second) {
void CCNode::insertBefore(CCNode* child, CCNode* before) {
this->addChild(child);
if (m_pChildren->containsObject(before)) {
if (
(before && m_pChildren->containsObject(before)) ||
(before = static_cast<CCNode*>(m_pChildren->firstObject()))
) {
child->setZOrder(before->getZOrder());
child->setOrderOfArrival(before->getOrderOfArrival() - 1);
}