From 32a86c530bdf893dda4c7e95f7e0ae3cc18645ae Mon Sep 17 00:00:00 2001 From: kaokei Date: Sat, 7 Sep 2024 13:18:22 +0800 Subject: [PATCH] Update Node.cpp setSiblingIndex support negative index Force index=0 when index smaller than -siblings.length. --- native/cocos/core/scene-graph/Node.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/native/cocos/core/scene-graph/Node.cpp b/native/cocos/core/scene-graph/Node.cpp index bc84ecf0d26..5ec8550dd2d 100644 --- a/native/cocos/core/scene-graph/Node.cpp +++ b/native/cocos/core/scene-graph/Node.cpp @@ -353,7 +353,8 @@ void Node::setSiblingIndex(index_t index) { return; } ccstd::vector> &siblings = _parent->_children; - index = index != -1 ? index : static_cast(siblings.size()) - 1; + index = index >= 0 ? index : static_cast(siblings.size()) + index; + index = index >= 0 ? index : 0; index_t oldIdx = getIdxOfChild(siblings, this); if (index != oldIdx) { if (oldIdx != CC_INVALID_INDEX) {