Music problems.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nick888

Hi guys.

I have a Menu Game Scene and when i open my game starts and the music of the menu scene. When i press the New Game button the music stops and start the music of the Gameplay.So far all good.
But,when i press the Load Game button the the music from the menu scene and the music from the gameplay are played on top of each other. With a few words the two musics sounds together.

Any idea please?
Thank you.

What exactly is going on? The “menu scene” music keeps playing even when the “Load Game” button is pressed? Do you have code in place to stop the “menu scene” music from playing when the “Load Game” button is pressed?

Ertain | 2019-11-13 09:26

We have the following situation:

The menu scene father Node has the following script:

func _on_NG_pressed():
	ad.hide_ad_banner()
	k=get_tree().change_scene("res://Scenes/World.tscn")
	sscore.score=0
	pass 

func _on_QG_pressed():
	get_tree().quit()
	pass 

func _on_LG_pressed():
	ad.hide_ad_banner()
	if  sl.bestscore>=50 && sl.bestscore<100:
		sl.bestscore=50
	if  sl.bestscore>=100 && sl.bestscore<170:
		sl.bestscore=100
	if  sl.bestscore>=170 && sl.bestscore<280:
		sl.bestscore=170
	if  sl.bestscore>=280:
		sl.bestscore=280
		k=get_tree().change_scene("res://Scenes/WinnerScene.tscn")
	if  sl.bestscore in [50,100,170,280]:
		var fortosi=load("res://Scenes/WorldBest.tscn")
		var ins=fortosi.instance()
		add_child(ins)
		visible= not visible
	else:
		k=get_tree().change_scene("res://Scenes/Forbiten.tscn")
	pass 

So when i press the New Game button the World scene opens. The main menu scene music stops automatically and the World scene music starts.

When i press the Load Game button the WorldBest scene opens.The main menu scene music doesn’t stop and the WorldBest scene music starts also. The two music songs sounds together.

Nick888 | 2019-11-13 10:05

Ok. I found the method stop() and i did this:

func _on_LG_pressed():
	$MenuMusic.stop()
	ad.hide_ad_banner()
	if  sl.bestscore>=50 && sl.bestscore<100:
		sl.bestscore=50
	if  sl.bestscore>=100 && sl.bestscore<170:
		sl.bestscore=100
	if  sl.bestscore>=170 && sl.bestscore<280:
		sl.bestscore=170
	if  sl.bestscore>=280:
		sl.bestscore=280
		k=get_tree().change_scene("res://Scenes/WinnerScene.tscn")
	if  sl.bestscore in [50,100,170,280]:
		var fortosi=load("res://Scenes/WorldBest.tscn")
		var ins=fortosi.instance()
		add_child(ins)
		visible= not visible
	else:
		k=get_tree().change_scene("res://Scenes/Forbiten.tscn")
	pass 

It worked, but i don’t really understand what’s the reason why with the New Game button i didn’t have a problem and i had a problem with the Load Game button.

Nick888 | 2019-11-13 10:17

Maybe this code could be the culprit?

if  sl.bestscore in [50,100,170,280]:
     var fortosi=load("res://Scenes/WorldBest.tscn")
     var ins=fortosi.instance()
     add_child(ins)

When the scene is changed, the menu music node may not be freed when the instance is added to the scene tree.

Ertain | 2019-11-13 17:42