MaxZieb
(Loves Hype)
May 10, 2020, 4:49pm
10
You can use a third party audio library
or
use these extensions that allows loading the same sound multiple times after the fact. I'd load the collision sound using the id of the object colliding.
↑ extension index
hypeDocument.loadSound
Load soundfiles from the library and plays them back.
/**
* hypeDocument.loadSound 1.0
* @param {String} soundname without extention (mp3/ogg/wav)
* @param {String} uniqueId to load the same sound multiple times (optional)
* @require getPrivateContainer
* @return {HTMLAudioElement}
*/
hypeDocument.loadSound = function(soundname, uniqueId){
var soundId = soundname+'_-_'+( (uniqueId===undefined)?'':uniqueId);
if (!hypeDocument.hasOwnProperty('_…
Make sure to unload and garbage collect if you use the method:
↑ extension index
hypeDocument.unloadAllSoundsByName
resets all the audio element and removes them from the DOM given the library name (without mp3/ogg)
You will only need this if you are concerned with garbage collection.
/**
* hypeDocument.unloadAllSoundsByName 1.0
* @param soundname
*/
hypeDocument.unloadAllSoundsByName = function(soundname){
if (!hypeDocument.hasOwnProperty('_sounds')) return false;
var success = false;
for(var id in hypeDocument._sounds) {
if(id.ind…