Skip to content

Instantly share code, notes, and snippets.

@richtaur
Created October 20, 2009 06:55
Show Gist options
  • Save richtaur/214079 to your computer and use it in GitHub Desktop.
Save richtaur/214079 to your computer and use it in GitHub Desktop.
Diggy Audio example
/**
* DGE audio Object. This is how I want the API to look
*/
/*
DGE.audio = {
mute : function() {
},
volume : function() {
},
music : {
get : get,
set : set
},
sfx : {
get : get,
set : set
}
};
*/
// Global methods
DGE.audio.mute();
DGE.audio.volume(Object); // undefined = return volume; Number = set volume
// Setting up sound FX
var sfx = DGE.audio.sfx.set({
levelUp : 'level_up.mp3',
itemGet : 'item_get.mp3'
}); // For future release: callback (complete, error)
// Sound FX methods
sfx.levelUp.play();
sfx.levelUp.pause();
sfx.levelUp.stop();
sfx.levelUp.single(Boolean);
sfx.levelUp.multiple(Boolean);
// Retrieve sound FX
var levelUp = DGE.audio.sfx.get('levelUp');
// Setting up music
var music = DGE.audio.music.set({
theme : 'theme.mp3',
battle1 : 'battle1.mp3',
battle2 : 'battle2.mp3'
}); // For future release: callback (complete, error)
// Music methods
music.theme.loop(Boolean);
music.theme.play();
music.theme.pause();
music.theme.stop();
DGE.audio.music.fadeIn(Number /* ms */);
DGE.audio.music.fadeOut(Number /* ms */);
DGE.audio.music.stop();
// Retrieve music
var theme = DGE.audio.music.get('theme');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment