aqualogue/main/SFX.js

45 lines
732 B
JavaScript
Raw Normal View History

2016-05-18 21:42:58 -05:00
SFX = (function() {
var S = createjs.Sound;
var SFX = {};
2016-05-18 22:30:44 -05:00
SFX.volume = 0.8;
2016-05-18 21:42:58 -05:00
var sounds = [
"dash",
2016-05-18 22:30:44 -05:00
"menu",
"select",
"unavailable",
"wall",
"door",
"key",
"save",
"bosshit",
"explode",
2016-05-18 21:42:58 -05:00
];
SFX.init = function() {
sounds.forEach(function(sound) {
S.registerSound("assets/sfx/" + sound + ".ogg", "S_" + sound);
});
}
var playing = {};
SFX.play = function(name) {
if (playing[name]) {
playing[name].stop();
playing[name].play();
} else {
playing[name] = S.play("S_" + name, {interrupt: createjs.Sound.INTERRUPT_ANY, loop: 0});
}
playing[name].volume = SFX.volume;
}
SFX.stop = function(name) {
if (playing[name]) {
playing[name].stop();
}
}
return SFX;
})();