Thursday, February 20, 2025
spot_img

Node setSiblingIndex() – Cocos Creator


Hello All,

Is there a technique to overwrite the bottom class operate to outline our personal implementation?

Requirement :- Since zIndex help shouldn’t be out there anymore in 3.8.2 I’m utilizing setSiblingIndex() to replace the precedence of the node as per my recreation requirement. I’ve to shuffle the node precedence few time.

Instance :- Kids in node are

child1, child2, child3, child4, child5
to
child1, child2, child5, child3, child4
to
child1, child2, child5, child4, child3

I’m setting the setSiblingIndex() worth to a excessive quantity by holding a reference of quantity connect to sort of picture stored in node.

However base code is at all times push the aspect to the tip if index is bigger than no of youngsters. So I can’t depart hole inside index vary.

Please tag core member for replace or steering the way to overwrite it.
Thanks

Under is the core definition of operate.

/**
 * @en Set the sibling index of the present node in its father or mother's kids array.
 * @zh 设置当前节点在父节点的 kids 数组中的位置。
 */
public setSiblingIndex (index: quantity): void {
    if (!this._parent) {
        return;
    }
    if (this._parent._objFlags & Deactivating) {
        errorID(3821);
        return;
    }
    const siblings = this._parent._children;
    index = index !== -1 ? index : siblings.size - 1;
    const oldIndex = siblings.indexOf(this);
    if (index !== oldIndex) {
        siblings.splice(oldIndex, 1);
        if (index 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles