ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
主要是用load的一些方法 ![](https://box.kancloud.cn/e11bcedfd2c4a177ef6e0d19c3a6139b_763x402.png) 加载事件,单个和全部 ![](https://box.kancloud.cn/4857f5f213e05f638e56d12e8cb14111_918x433.png) 值得一说的是我们的资源加载必须写在preload周期里。 一个带背景的和百分比文字的 进度加载场景 ~~~ var boot = function(game){ var progressText; this.init=function(){} this.preload = function(){ console.log("这里是boot") game.load.image('loading_bg','../img/loadingBg.png') var sprite = game.add.image(game.world.centerX,game.world.centerY,'loading_bg') sprite.anchor = {x:0.5,y:0.5} //设置图片锚点 progressText = game.add.text(game.world.centerX,game.world.centerY+30,'0%',{fill:'#fff',fontSize:"16px"}) progressText.anchor = {x:0.5,y:0.5} // 监听加载完一个文件的事件 game.load.onFileComplete.add(function (progress) { progressText.text = progress + '%'; }); // 监听加载完毕事件 game.load.onLoadComplete.add(onLoad); // 最小展示时间,示例为2秒 var deadLine = false; setTimeout(function () { deadLine = true; }, 1000); // 加载完毕回调方法 function onLoad() { if (deadLine) { // 已到达最小展示时间,可以进入下一个场景 game.state.start('load'); } else { // 还没有到最小展示时间,1秒后重试 setTimeout(onLoad, 500); } } } this.create = function(){ } this.updata = function(){} this.render = function(){} } ~~~