【cocos creator】嵌套预加载进度条显示

嵌套预加载进度条显示


    progressFinish() {
        this.load_count++
        //"加载main场景"
        if (this.load_count >= TOTAL_LOAD_COUNT) {
            cc.director.preloadScene('main', (completedCount, totalCount) => {
                this.setProgress(completedCount / totalCount, 0, 0.6);
            }, (e) => {
                cc.resources.load(`prefabs/MainUi`, (completedCount, totalCount) => {
                    this.setProgress(completedCount / totalCount, 0.6);
                }, () => {
                        cc.director.loadScene('main');
                });
            });
        }
    }

    //设置进度条
    setProgress(num: number, start = 0, end = 1) {
        if (isNaN(num)) num = end;
        if (start) num = start + num * (end - start);
        if (num > end) num = end;
        this.label_progress.string = `${Math.ceil(num * 100)}%`;
        // this.ani.x = this.progress.x + num * this.progress.width;
        this.progress.getComponent(cc.Sprite).fillRange = num;
    }

你可能感兴趣的:(cocos,cocos-creator)