Add SFX handler

This commit is contained in:
RedEnchilada 2016-05-18 21:42:58 -05:00
parent 83da0ee4bf
commit 8f73970f16
2 changed files with 37 additions and 0 deletions

View file

@ -7,6 +7,7 @@ Game = (function() {
Renderer.init(initScene);
Music.init();
SFX.init();
function initScene() {
// Run callback to set the inital scene.

36
main/SFX.js Normal file
View file

@ -0,0 +1,36 @@
SFX = (function() {
var S = createjs.Sound;
var SFX = {};
SFX.volume = 1;
var sounds = [
"dash",
];
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;
})();