Necesito hacer un proyecto para mi curso de TI en la escuela. Implementé un juego Jump N Run en Visual Studio Code con Javascript. Tiene 4 niveles y funciona con html. Mi maestro ahora dijo que tengo que agregar música de fondo. Y no tengo ni idea de por dónde empezar. Realmente no soy tan bueno en TI y, por lo tanto, realmente no sé qué información se necesita para ayudarme con esa pregunta. Podría enviar toda mi carpeta si fuera necesario. Gracias de antemano. PD: Necesito terminar para el final de la semana.
Puede hacer esto en JavaScript con bastante facilidad.
// 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 levelEsto debería ser suficiente para empezar, espero que ayude