1 Star 0 Fork 0

余赟昊 / Flappy-polimin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
StaticResoursesUtil.js 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
余赟昊 提交于 2020-11-16 20:57 . 我修复了不能连点的bug
//静态资源管理类
class StaticResoursesUtil{
constructor(){
this.images = new Object();
}
loadImage(jsonURL, callback){
//用ajax读取文件
let self = this;
let xhr = new XMLHttpRequest();
xhr.open("get",jsonURL);
xhr.send(null);
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
if(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304){
let loadedNum = 0;
//将json转化为js对象
let jsonObj = JSON.parse(xhr.responseText);
// console.log(jsonObj);
for(let i = 0; i < jsonObj.images.length; ++i){
let img = new Image();
img.src = jsonObj.images[i].src;
img.onload = function(){
//加载好的图片数量加一
loadedNum++;
//保存在自己的images属性里
// console.log(self);
self.images[jsonObj.images[i].name] = img;
// console.log(self.images);
callback(loadedNum,jsonObj.images.length,self.images)
}
}
}
}
}
}
}
1
https://gitee.com/yu_yunhao/flappy-polimin.git
git@gitee.com:yu_yunhao/flappy-polimin.git
yu_yunhao
flappy-polimin
Flappy-polimin
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891