How to play a global sound?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zylann
:warning: Old Version Published before Godot 3 was released.

Simple question, what is the best way to play a global stereo sound?
I always used SamplePlayers with sample libraries at the moment, but now I need something more “global”…

:bust_in_silhouette: Reply From: brunosxs

You could create a scene that has the music node , and then make a singleton(autoload) of it.

Controlling it would be just a matter of calling its functions or variables from any other script of your game.

It would be loaded globally and you’d be able to play or pause songs that would play between scenes.

Have a look at godot’s singleton page

EDIT:

Looks like your explanation was a little misleading for me, so now that I understood:

You should use “SamplePlayer” instead of SamplePlayer2D.
The main difference between the two is exactly this: SamplePlayer plays globaly on a scene, with no regards to the camera or viewport.

I dont want to play a song/stream, but a sound that has no spatial position. The problem with SamplePlayer is they are affected by the camera, I don’t want that. But I also don’t require the sound to be streamed, because it’s just a sound FX.

Zylann | 2016-04-14 21:51

Then, you should use “SamplePlayer” instead of SamplePlayer2D.
The main difference between the two is exactly this: SamplePlayer plays globaly on a scene, with no regards to the camera or viewport.

brunosxs | 2016-04-14 22:03

Sorry, I wrote “SamplePlayer” but I meant “SamplePlayer2D” indeed. So I’ll use SamplePlayer for global sounds now :slight_smile:

Zylann | 2016-04-15 00:58