加载界面中一个进度条,因为本来加载的东西不多,基本就是一闪而过,想给他减速,用了相关定时器函数,但它们都是异步的,无法达到其效果。有什么办法让进度条模拟走慢些吗
简单点,给个加速动力值。
可以在update里(这里举例)
speed = 10; // 加速率
maxLength = 200; // 进度条总限制长度
curMaxLength = 0; // 当前进度条最大限制长度
loadResCount = 0; // 加载资源总数
loadingOver = false; // 是否全部加载完成
prBar: cc.Node = null; // 进度条
loadData() {
this.loadResCount = 100;
let normalize = this.maxLength / this.loadResCount; // 每个文件占比
load... this.curMaxLength + normalize // this.curMaxLength + normalize 是在load 加载完毕回调 中+normalize
load... this.curMaxLength + normalize
load... this.curMaxLength + normalize
load... this.curMaxLength + normalize
load... this.curMaxLength + normalize
load... this.curMaxLength + normalize
}
update(dt) {
if (!this.loadingOver) {
let curLength = this.prBar.width;
this.prBar.width = curLength >= this.curMaxLength ? curLength + (this.speed * dt) : curLength;
if (this.prBar.width >= this.maxLength) {
this.loadingOver = true;
// OverLoad 加载结束 处理你想处理的逻辑 比如释放资源。。。
this.OverLoad();
}
}
}
随便写的伪代码, 提供大概思路你自己看把 反正就是给个速率的概念就行了 想快想慢随便你。
谢谢,晚些试下
看一下,这里只有思路哈,你直接复制进去肯定是不行的,而且我没写的很严谨你自己优化一下把。