I need to do a project for my IT course in school. I implemented a Jump N Run Game in Visual Studio Code with Javascript. It has 4 levels and works with html. My teacher now said that I have to add background music. And I have no idea where to start . I'm really not that good in IT and therefore I don't really know what information is needed in order to help me out with that question. I could send my whole folder in if needed. Thank you in advance. P.S.: I need to be finished by the end of the week.
You can do this in JavaScript fairly easily.
// Create a variable to reference your music file
// that is stored in a new Audio object
const music = new Audio("./pathToMusicFile.wav");
// Add an event listener to detect user interaction
// and add a callback function that will run when
// the event occurs. I've added it to the window
// here, but you could add the event to the button
// that starts your game. I've named the callback
// function playMusic here
window.addEventListener("click", playMusic);
// Function to play the music
// in a continuous loop
function playMusic() {
// start the music
music.play();
// make the music loop continuously
music.loop = true;
}
// Note: If you want to stop the music at some point
// you can do it like this: music.stop()
// which you might want to do when each level of your
// game ends, and then perhaps, play a different tune
// for the next level
This should be enough to get you started, I hope it helps