loading预加载
cc.Class({
extends: cc.Component,
properties: {
progressLabel: cc.Label,
tipsLabelNode: cc.Node,
},
preLoadResDir() {
cc.loader.loadResDir("sound", (completedCount, totalCount, item) => {
}, (err, res) => {
if (err) { console.log(err) };
cc.log("sound已预加载");
})
cc.loader.loadResDir("bg", (completedCount, totalCount, item) => {
}, (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) + "%";
}, (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() {
},
});