RichText的Label Pool根本不起作用
RichText设计里面用到了对象池来避免重复创建Label Node,但是实现的有问题。
let pool = new js.Pool(function (node) {
if (CC_EDITOR) {
cc.isValid(node) && node.destroy();
return false;
}
if (CC_DEV) {
cc.assert(!node._parent, ‘Recycling node’s parent should be null!’);
}
if (!cc.isValid(node)) {
return false;
} else {
let outline = node.getComponent(cc.LabelOutline);
if (outline) {
outline.width = 0;
}
}return true;}, 20);
onDestroy () {
for (let i = 0; i < this._labelSegments.length; ++i) {
this._labelSegments[i].removeFromParent();
pool.put(this._labelSegments[i]);
}
},
pool.put 这行代码,根本不会将labelSegment放入池子中。在判断能否放进池子的判断!cc.isValid(node) 就已经返回false了。
-
Creator 版本: 2.4.13
-
目标平台:所有
-
重现方式:创建一个RichText,更新内容,然后销毁。