cocos3.10 html 用代码生成widget ,保存起来,重复添加到场景速度为什么很慢

来源:互联网 发布:网络教育毕业总结 编辑:程序博客网 时间:2024/06/05 00:44

我用代码生成了很多个widget大概有500个,把它存起来,等待需要的时候添加到场景,但是在手机上需要花费3秒钟左右的时间,我不清楚这个时间是花费在哪里的,最后发现是添加到场景的时候调用addchild,方法,它会调用节点的onEnter方法

onEnter: function () {
        var locListener = this._touchListener;
        if (locListener && !locListener._isRegistered() && this._touchEnabled)
            cc.eventManager.addListener(locListener, this);
        if(!this._usingLayoutComponent)
            this.updateSizeAndPosition();
        cc.ProtectedNode.prototype.onEnter.call(this);
    },

在onEnter方法里面会判断是否使用_usingLayoutComponent,如果没有使用,就调用函数 this.updateSizeAndPosition();

在这里花费了大量的时间。

只需要调用方法widget 的setLayoutComponentEnabled(true);

就可以越过这条this.updateSizeAndPosition();耗时的函数


阅读全文
0 0
原创粉丝点击