You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publiconSortChildren(): void{const children =this.children;for(leti=children.length-1;i>=0;--i){(children[i]asany)._siblingIndex=i;}NodeEventProcessor.callbacksInvoker.emit(DispatcherEventType.MARK_LIST_DIRTY);this.emit(cc.NodeEventType.CHILDREN_ORDER_CHANGED);}
Use Case
目前 cocos 中 如果要实现 node的排序 要基于 setSiblingIndex() 方法.
这个方法 每次交换 节点 都要 执行很多复杂的操作. 偶尔改变一两个节点的顺序 还能接受.
但是如果要大批量大范围的改动 就很低效率.
改变任何一个node的顺序, 都会执行 splice/push, _updateSiblingIndex, _onSiblingIndexChanged, onUpdatingSiblingIndex.
但是当批量排序时, 通常我们只需要 在排序后, 统一执行一次这些方法.
逻辑可能是这样的:
node.children.sort((a, b) => a._siblingIndex- b._siblingIndex)
对所有children 进行一次性批量排序.按照上述逻辑来实现批量排序 性能会更好. 希望官方能够提供类似方法.
Problem Description
如上所述
Proposed Solution
No response
How it works
No response
Alternatives Considered
无
Additional Information
No response
The text was updated successfully, but these errors were encountered: