preload all category images in loader.js

This commit is contained in:
mnvdk 2020-04-15 22:33:49 +02:00
parent 85d6e70ff6
commit e1411bcd0d
2 changed files with 17 additions and 3 deletions

View File

@ -86,7 +86,7 @@ class Loader{
}), url)
}
assets.img.forEach(name => {
assets.img.forEach(name=>{
var id = this.getFilename(name)
var image = document.createElement("img")
var url = gameConfig.assets_baseurl + "img/" + name
@ -132,6 +132,20 @@ class Loader{
return
}
assets.categories //load category backgrounds to DOM
.filter(cat=>cat.songSkin && cat.songSkin.bg_img)
.forEach(cat=>{
let name = cat.songSkin.bg_img
var id = this.getFilename(name)
var image = document.createElement("img")
var url = gameConfig.assets_baseurl + "img/" + name
this.addPromise(pageEvents.load(image), url)
image.id = name
image.src = url
this.assetsDiv.appendChild(image)
assets.image[id] = image
})
snd.buffer = new SoundBuffer()
snd.musicGain = snd.buffer.createGain()
snd.sfxGain = snd.buffer.createGain()

View File

@ -107,7 +107,6 @@ class SongSelect{
category.songSkin.sort = sortCount
sortCount += 1
}
this.songSkin[category.title] = category.songSkin
}
}
@ -2326,7 +2325,8 @@ class SongSelect{
drawBackground(cat, sort){
if(this.songSkin[cat] && this.songSkin[cat].bg_img){
this.songSelect.style.backgroundImage = "url('assets/img/" + this.songSkin[cat].bg_img + "')"
let filename = this.songSkin[cat].bg_img.slice(0, this.songSkin[cat].bg_img.lastIndexOf("."))
this.songSelect.style.backgroundImage = "url('" + assets.image[filename].src + "')"
}else{
if(assets.image["bg_genre_" + sort]){
this.songSelect.style.backgroundImage = "url('" + assets.image["bg_genre_" + sort].src + "')"