26 lines
531 B
JavaScript
26 lines
531 B
JavaScript
class Resources {
|
|
constructor() {
|
|
this.total = 0;
|
|
this.loading = 0;
|
|
this.resources = {};
|
|
|
|
this.load('ball');
|
|
this.load('bar');
|
|
}
|
|
|
|
|
|
load(res) {
|
|
let _this = this;
|
|
this.total++;
|
|
this.loading++;
|
|
this.resources[res] = new Image();
|
|
this.resources[res].onload = function () {
|
|
_this.loading--;
|
|
}
|
|
this.resources[res].src = 'assets/imgs/' + res + '.png';
|
|
}
|
|
|
|
get(res) {
|
|
return this.resources[res];
|
|
}
|
|
}; |