Skip to content

Commit

Permalink
Update node.ts setSiblingIndex support negative index
Browse files Browse the repository at this point in the history
eg.
-1 equals siblings.length -1.
-2 equals siblings.length -2.
-3 equals siblings.length -3.
  • Loading branch information
kaokei authored Aug 31, 2024
1 parent 6fe9ff7 commit 1e2caa0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cocos/scene-graph/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
return;
}
const siblings = this._parent._children;
index = index !== -1 ? index : siblings.length - 1;
index = index >= 0 ? index : siblings.length + index;
const oldIndex = siblings.indexOf(this);
if (index !== oldIndex) {
siblings.splice(oldIndex, 1);
Expand Down

0 comments on commit 1e2caa0

Please sign in to comment.