Skip to content

Commit

Permalink
Switch to async preloading.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDiBernardo committed Aug 26, 2024
1 parent 8d5fa53 commit a2b6d27
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function happyDance(bug) {
}, bugDanceDuration);
}

document.addEventListener("DOMContentLoaded", () => {
async function startGame() {
const splashScreen = document.getElementById("splash-screen");
const scrollableArea = document.getElementById("scrollable-area");
const rockTemplate = document.getElementById("rock-template");
Expand Down Expand Up @@ -142,19 +142,20 @@ document.addEventListener("DOMContentLoaded", () => {
}
}

function initialize() {
preloadAssets()
.then(() => {
createRocks();
})
.catch((error) => {
console.error("Error preloading assets:", error);
})
.finally(() => {
// Hide splashscreen regardless of whether prefetch was successful.
hideSplashScreen();
});
async function initialize() {
try {
await preloadAssets();
} catch (error) {
console.error("Error preloading assets:", error);
} finally {
createRocks();
hideSplashScreen();
}
}

initialize();
}

document.addEventListener("DOMContentLoaded", () => {
startGame();
});

0 comments on commit a2b6d27

Please # to comment.