Node setSiblingIndex()

Hi All,

Is there a way to overwrite the base class function to define our own implementation?

Requirement :- Since zIndex support is not available anymore in 3.8.2 I am using setSiblingIndex() to update the priority of the node as per my game requirement. I have to shuffle the node priority few time.

Example :- Children in node are

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

I am setting the setSiblingIndex() value to a high number by keeping a reference of number attach to type of image kept in node.

But base code is always push the element to the end if index is greater than no of children. So I cannot leave gap within index range.

Please tag core member for update or guidance how to overwrite it.
Thanks

Below is the core definition of function.

/**
 * @en Set the sibling index of the current node in its parent's children array.
 * @zh 设置当前节点在父节点的 children 数组中的位置。
 */
public setSiblingIndex (index: number): void {
    if (!this._parent) {
        return;
    }
    if (this._parent._objFlags & Deactivating) {
        errorID(3821);
        return;
    }
    const siblings = this._parent._children;
    index = index !== -1 ? index : siblings.length - 1;
    const oldIndex = siblings.indexOf(this);
    if (index !== oldIndex) {
        siblings.splice(oldIndex, 1);
        if (index < siblings.length) {
            siblings.splice(index, 0, this);
        } else {
            siblings.push(this);
        }
        this._parent._updateSiblingIndex();
        if (this._onSiblingIndexChanged) {
            this._onSiblingIndexChanged(index);
        }
        this._eventProcessor.onUpdatingSiblingIndex();
    }
}

can you please elaborate how there is a gap within index range, can you please share logs

Hi @s_agarwal

I am working on slot game. We have symbol which might have move priority due the amount it is paying out.

In cocos 2D i used to set the “zindex” with higher value to move that symbol/sprite/image in front/top of other images. I don’t want to track the order of symbol or priority associated to it, hence we give a range to symbol indicating that this will be above other.

As symbol are categorizes in 4 sets, “pictures, royal, scatter, wild”.

In creator 3.8.2 we have only option to use setSiblingIndex() which work on the no of child nodes(definition attached in main post). Hence when i assign a bigger number as index it always push symbol at the last and i am not able to achieve the desired result even though i have same symbols.

See attached image since they are same symbol order should be top to bottom, left to right.

Currently the code is maintaining the order based on index of child while i believe it should be a separate property on node based on which order is rearranged.

If we go with the current approach i have to maintain the order as well as priority tightly coupled in my implementation and the leverage of zindex which used to be there is not available anymore.