Skip to content

Commit

Permalink
Added some improvements to audiopool
Browse files Browse the repository at this point in the history
  • Loading branch information
satanas committed Mar 9, 2015
1 parent eee10f1 commit 93a2f22
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions audiopool.js
Expand Up @@ -3,6 +3,7 @@
var AudioPool = function(keys) {
this.keys = keys;
this.sounds = []
this.index = 0;

for(var i=0; i<this.keys.length; i++) {
this.sounds.push(game.add.audio(this.keys[i]));
Expand All @@ -14,7 +15,15 @@ AudioPool.prototype.constructor = AudioPool;
AudioPool.prototype.randomPlay = function(loop, volume) {
var volume = (volume === undefined) ? 1.0 : volume
var loop = (loop === undefined) ? false : loop
var index = Math.floor(Math.random() * this.keys.length);
this.index = Math.floor(Math.random() * this.keys.length);

this.sounds[index].play('', 0, 1, volume, loop);
this.sounds[this.index].play('', 0, 1, volume, loop);
};

AudioPool.prototype.stop = function() {
this.sounds[this.index].stop();
};

AudioPool.prototype.resume = function() {
this.sounds[this.index].play();
};

0 comments on commit 93a2f22

Please sign in to comment.