I’m having trouble with…
The error I’m getting is:…
My code looks like this:
Example
*commend
Indent
```Now I have another big question, to have who gives me a hand.
I am reading and learning about javascrypt, and I would like to get something that I think could be useful for those of us who want to include sounds in our games.
I have read of an event to preload all the audio files in the cache and be able to play them without delay.
My problem is that I know how to apply it correctly in the playSound function
I leave the function dedicated to the sound that includes CS, and the event, who can help me.
PlaySound function:
code:
function playSound(source) {
for (var existingAudios = document.getElementsByTagName(“audio”); existingAudios.length;) {
existingAudios[0].parentNode.removeChild(existingAudios[0]);
}
if (typeof hashes != ‘undefined’ && hashes[source]) {
source += “?hash=” + hashes[source];
}
var audio = document.createElement(“audio”);
if (audio.play) {
audio.setAttribute(“src”, source);
document.body.appendChild(audio);
audio.play();
}
}
Event to preload the files before playing them:
code:
audio.addEventListener(‘canplaythrough’,function(){