loading预加载

loading预加载

cc.Class({
    extends: cc.Component,

    properties: {
        progressLabel: cc.Label,
        tipsLabelNode: cc.Node,
    },
    //预加载资源
    preLoadResDir() {
        cc.loader.loadResDir("sound", (completedCount, totalCount, item) => {
            // this.progressLabel.string = "正在准备:" + parseInt((completedCount / totalCount) * 100) + "%";
        }, (err, res) => {
            if (err) { console.log(err) };
            cc.log("sound已预加载");
        })
        cc.loader.loadResDir("bg", (completedCount, totalCount, item) => {
            // this.progressLabel.string = "正在准备:" + parseInt((completedCount / totalCount) * 100) + "%";
        }, (err, res) => {
            if (err) { console.log(err) };
            cc.log("bg已预加载");
        })
    },
    //预加载场景
    preLoadScene() {
        cc.director.preloadScene("gameScene", (completedCount, totalCount, item) => {
            this.progressLabel.string = "场景加载中:" + parseInt((completedCount / totalCount) * 100) + "%";
            // this.progressBar.width = 506 * (completedCount / totalCount);
        }, (error, asset) => {
            if (error) {
                cc.log("场景加载失败");
                return;
            } else {
                cc.director.loadScene("gameScene");
                cc.log("场景加载成功");
            };
        })
    },
    //初始化动画
    iniAnim() {
        cc.tween(this.tipsLabelNode)
            .to(1, { opacity: 255 }, { easing: "sineIn" })
            .start();
    },
    onLoad() {
        this.progressLabel.string = "首次加载时间较长,请耐心等待";
        this.tipsLabelNode.opacity = 0;
        this.iniAnim();
        this.preLoadResDir();
        this.preLoadScene();

    },

    start() {

    },

    // update (dt) {},
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值