From 1e2caa02f0c90dd81e5fb5a04410308c555e4438 Mon Sep 17 00:00:00 2001 From: kaokei Date: Sat, 31 Aug 2024 15:41:31 +0800 Subject: [PATCH] Update node.ts setSiblingIndex support negative index eg. -1 equals siblings.length -1. -2 equals siblings.length -2. -3 equals siblings.length -3. --- cocos/scene-graph/node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 421e1a3f827..eebc530744b 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -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);