1 decade ago by afflicto
I needed a 'loop' function for my Sounds as well as pause and unPause functions.
So here:
plugin
To use it, simply
1: copy the above plugin code and paste it in 'lib/plugins/afflicto/sound.js'.
2: add 'plugins.afflicto.sound' to your main.js requires() block.
Then, if you have an entity that has a footsteps sound.. you could do something like this:
Example
So here:
plugin
ig.module( 'plugins.afflicto.sound' ) .requires( 'impact.sound' ) .defines(function(){ "use strict"; ig.Sound.inject({ playCount: 0, setVolume: function(volume) { this.volume = volume; if (this.currentClip) { this.currentClip.volume = ig.soundManager.volume * this.volume; } }, play: function() { if( !ig.Sound.enabled ) { return; } this.playCount++; this.currentClip = ig.soundManager.get( this.path ); this.currentClip.volume = ig.soundManager.volume * this.volume; this.currentClip.play(); }, continue: function() { if (this.currentClip) { if (this.currentClip.currentTime < this.currentClip.duration) { this.currentClip.play(); }else { this.play(); } }else { this.play(); } }, pause: function() { if (this.currentClip) { this.currentClip.pause(); } }, unPause: function() { if (this.currentClip) { this.currentClip.play(); } }, }); });
To use it, simply
1: copy the above plugin code and paste it in 'lib/plugins/afflicto/sound.js'.
2: add 'plugins.afflicto.sound' to your main.js requires() block.
Then, if you have an entity that has a footsteps sound.. you could do something like this:
Example
EntityPlayer = ig.Entity.extend({ footsteps: new ig.Sound('path/to/footsteps.*'), update: function() { if (this.isWalking) { //you can do unPause here, //but continue will re-start it if it's done playing. //effectively looping as long as you continue calling 'continue'. this.footsteps.continue(); }else { //simply pauses it. nothing more. this.footsteps.pause(); } }, });