Skip to content

Instantly share code, notes, and snippets.

@stagas
Created September 13, 2010 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stagas/577291 to your computer and use it in GitHub Desktop.
Save stagas/577291 to your computer and use it in GitHub Desktop.
var Sfx = function() {
this.sounds = {}
this.active = false
this.max = 12
this.playing = 0
}
Sfx.prototype = {
init: function() {
this.active = true
}
, add: function(category, snd) {
if (!this.active) return
if (typeof this.sounds[category] === 'undefined') {
this.sounds[category] = []
}
var s = new Audio('/sfx/' + snd + '.ogg')
this.sounds[category].push(s)
}
, play: function(category, volume) {
if (!this.active) return
var self = this
, rs = fisherYates(this.sounds[category])
rs[0].play()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment