diff --git a/web/_js/main/time.js b/web/_js/main/time.js index 04af6408..f7911f68 100644 --- a/web/_js/main/time.js +++ b/web/_js/main/time.js @@ -106,18 +106,20 @@ async function updateBackground(newPeriod = currentPeriod, newVariation = curren } const canvas = document.createElement('canvas') const context = canvas.getContext('2d') - for await (const url of layerUrls) { + + layers.length = layerUrls.length + await Promise.all(layerUrls.map(async (url, i) => { const imageLayer = new Image() await new Promise(resolve => { imageLayer.onload = () => { context.canvas.width = Math.max(imageLayer.width, context.canvas.width) context.canvas.height = Math.max(imageLayer.height, context.canvas.height) - layers.push(imageLayer) + layers[i] = imageLayer resolve() } imageLayer.src = url }) - } + })) for (const imageLayer of layers) { context.drawImage(imageLayer, 0, 0)