Feature Request: Add a simple `loadAudio` function.
jcollard opened this issue · comments
I've added audio to my Invaders
demo by creating a simple addAudio
function. I think it might be a straightforward and easy addition to the platform to make things simple.
You could even provide a library of sound effects. Maybe provide a loadAudioFromURL(URL)
and a loadAudio(KnownSound)
.
A feature for down the road might be to add a preLoad
function which is a special per project function that executes before all of the start
methods and allows to load larger audio? OOOOR... maybe this is just getting too far ahead and simple is better.
Anyway, here is the relevant snippet from Invaders
:
function start() {
self.fireSound = addSound('https://github.com/jcollard/SoundFiles/blob/main/laser1.wav?raw=true');
self.blipSound = addSound('https://github.com/jcollard/SoundFiles/blob/main/blip.wav?raw=true');
self.gameOverSound = addSound('https://github.com/jcollard/SoundFiles/blob/main/gameover.wav?raw=true');
self.gameWonSound = addSound('https://github.com/jcollard/SoundFiles/blob/main/gamewon.wav?raw=true')
}
function addSound(src)
{
let audio = document.createElement("audio");
audio.src = src;
return audio;
}
Resolved with e251c17. Created addSound(name, url)
and playSound(name)
functions. Thanks for the suggestion!