Add SFX handler
This commit is contained in:
parent
83da0ee4bf
commit
8f73970f16
2 changed files with 37 additions and 0 deletions
|
@ -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
36
main/SFX.js
Normal 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;
|
||||
})();
|
Loading…
Add table
Reference in a new issue