Skip to content

Commit

Permalink
Update Node.cpp setSiblingIndex support negative index
Browse files Browse the repository at this point in the history
Force index=0 when index smaller than -siblings.length.
  • Loading branch information
kaokei authored Sep 7, 2024
1 parent 1e2caa0 commit 32a86c5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion native/cocos/core/scene-graph/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ void Node::setSiblingIndex(index_t index) {
return;
}
ccstd::vector<IntrusivePtr<Node>> &siblings = _parent->_children;
index = index != -1 ? index : static_cast<index_t>(siblings.size()) - 1;
index = index >= 0 ? index : static_cast<index_t>(siblings.size()) + index;
index = index >= 0 ? index : 0;
index_t oldIdx = getIdxOfChild(siblings, this);
if (index != oldIdx) {
if (oldIdx != CC_INVALID_INDEX) {
Expand Down

0 comments on commit 32a86c5

Please sign in to comment.