Jump to content

Sound Problem.


Recommended Posts

Hello there.


So i have a problem with sound, more exactly with music.

For some reason it doesnt want to pause or stop.

// these 2 IFs handle the resuming/pausing or stop/playif(soundChanged==true || musicChanged==true){	if(soundState==true && musicState==true)	{		backgroundSound.resume();	}}if(soundState==false || musicState==false) // so this is the IF that doesnt pause my sound{        console.log('pause');//i also put a log here like so, the log answers to my call but the music does not pause.	backgroundSound.pause();}//below is strictly for animations but also the 'Changed' vars become false so the above IFs wont repeat.if(musicChanged==true){	if(musicState==false)	{		buttonMusicSprite.animations.play('off', 32, true);	}	if(musicState==true)	{		buttonMusicSprite.animations.play('on', 32, true);	}	musicChanged=false;}if(soundChanged==true){	if(soundState==false)	{		buttonSoundSprite.animations.play('off', 32, true);	}	if(soundState==true)	{		buttonSoundSprite.animations.play('on', 32, true);	}	soundChanged=false;}

This happens in update.

So its like this, inside the music and sound buttons functions, i set the music and sound changed variables to true (soundChanged=true, musicChanged=true) while i also say soundstate=!soundState and musicState=!musicState.



The strange problem is that it works just fine while in menu, but as soon as i go to the game and then back to menu for example, then the music doesnt stop or pause (i tried with stop and play aswell).


If i come back to menu from level with music stoped, it resumes when i click, but if i come with music playing it doesnt pause if i click that buttons.







Same goes for level screen, not only in menu.






Theres no boolean or somethihng liek that to impair from pausing. That code i shown happens in the clean update().

Link to comment
Share on other sites

Upon a closer look i realised that i was calling the create function when i went back to menu from level. And it is there where i was using game.add.audio (backgroundSound).

So thats why i guess it didnt pause, cause it was creating another instance.



Now it works.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...