File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,8 @@ New Features
8686* Graphics chaining functions.
8787* Added Pointer.positionUp which records the last point at which the pointer left the screen (thanks @Cryszon , #676 )
8888* Phaser.Point.centroid static function added to calculate the centroid or midpoint of an array of points (thanks @lewster32 , #675 )
89+ * SoundManager.remove(sound) now lets you remove a sound from the SoundManager, destroying it in the process.
90+ * Sound.destroy will remove a sound and all local references it holds, optionally removing itself from the SoundManager as well.
8991
9092
9193Bug Fixes
Original file line number Diff line number Diff line change @@ -662,6 +662,7 @@ Phaser.Sound.prototype = {
662662
663663 /**
664664 * Stop playing this sound.
665+ *
665666 * @method Phaser.Sound#stop
666667 */
667668 stop : function ( ) {
@@ -697,6 +698,38 @@ Phaser.Sound.prototype = {
697698 this . currentMarker = '' ;
698699 this . onStop . dispatch ( this , prevMarker ) ;
699700
701+ } ,
702+
703+ /**
704+ * Destroys this sound and all associated events and removes it from the SoundManager.
705+ *
706+ * @method Phaser.Sound#destroy
707+ * @param {boolean } [remove=true] - If true this Sound is automatically removed from the SoundManager.
708+ */
709+ destroy : function ( remove ) {
710+
711+ if ( typeof remove === 'undefined' ) { remove = true ; }
712+
713+ this . stop ( ) ;
714+
715+ if ( remove )
716+ {
717+ this . game . sound . remove ( this ) ;
718+ }
719+
720+ this . markers = { } ;
721+ this . context = null ;
722+ this . _buffer = null ;
723+ this . externalNode = null ;
724+ this . onDecoded . dispose ( ) ;
725+ this . onPlay . dispose ( ) ;
726+ this . onPause . dispose ( ) ;
727+ this . onResume . dispose ( ) ;
728+ this . onLoop . dispose ( ) ;
729+ this . onStop . dispose ( ) ;
730+ this . onMute . dispose ( ) ;
731+ this . onMarkerComplete . dispose ( ) ;
732+
700733 }
701734
702735} ;
Original file line number Diff line number Diff line change @@ -57,7 +57,6 @@ Phaser.SoundManager = function (game) {
5757 /**
5858 * @property {array } _sounds - An array containing all the sounds
5959 * @private
60- * @default The empty array.
6160 */
6261 this . _sounds = [ ] ;
6362
@@ -364,8 +363,34 @@ Phaser.SoundManager.prototype = {
364363
365364 } ,
366365
366+ /**
367+ * Removes a Sound from the SoundManager. The removed Sound is destroyed before removal.
368+ *
369+ * @method Phaser.SoundManager#remove
370+ * @param {Phaser.Sound } sound - The sound object to remove.
371+ * @return {boolean } True if the sound was removed successfully, otherwise false.
372+ */
373+ remove : function ( sound ) {
374+
375+ var i = this . _sounds . length ;
376+
377+ while ( i -- )
378+ {
379+ if ( this . _sounds [ i ] === sound )
380+ {
381+ this . _sounds [ i ] . destroy ( false ) ;
382+ this . _sounds . splice ( i , 1 ) ;
383+ return true ;
384+ }
385+ }
386+
387+ return false ;
388+
389+ } ,
390+
367391 /**
368392 * Adds a new Sound into the SoundManager and starts it playing.
393+ *
369394 * @method Phaser.SoundManager#play
370395 * @param {string } key - Asset key for the sound.
371396 * @param {number } [volume=1] - Default value for the volume.
You can’t perform that action at this time.
0 commit comments