dimanche 23 mai 2021

JavaScript function sound looped

I'm just new to JavaScript and I'm having trouble at the mp3 loop on function, but it doesn't loop when it's not on the function. I wanted to play the audio once while still on the function. Here is an example

var winmsc = new Audio("../audio/win.mp3");
winmsc.loop = false;
var gend = false; // (for my game to end)
var a = 1;

if (a == 1) {
gend = true;
}

if (gend == true) {
endscreen();
}

function endscreen() {
winmsc.play();
}

Aucun commentaire:

Enregistrer un commentaire