Hi all,
I was wondering if there is ever a reason to not use an autoload to handle music in your game? SFX is different, because of the number of different effects and positioning, so it makes sense for each scene to handle their effects themselves, but to make music flow effectively, I feel like you should always use an autoload. You can easily control which music file you want to play and have complete control to make sure music doesn’t play over each other. Does anyone agree or disagree?
I agree, I’ve been playing around with static functions and variables along side class_names. It’s almost the same thing, but you don’t actually have to register an auto load. Not sure of draw backs.
Yes, I agree.
I can’t think of any drawbacks with my current knowledge.
That’s how I do it, I have a very limited number of autoloads, but the overarching main one that handles save and exit functions also handles the function to start, stop, pause, and queue music.
I somehow started thinking about this again. I guess it may depend on how music is used. If it’s a different song per level, area, sequenced with cutscenes, having a Singleton my not be really practical.
You may want a global volume option but a dedicated music audio bus can take care of that. And a music class that can force music volume during a cutscenes.
I think it could be practical to keep music player class in every applicable scene used…
For my first game, which is still in development, I avoided using an autoload for music, on the basis, a) I was worried of going over-the-top and creating too many autoloads, and b) I was naive, and didn’t know any better.
I’ve since wondered a couple of times if I should’ve used a music autoload, and, as per the posts in this thread, a music autoload is a great idea for centralizing music. That said, the mechanism I’ve used also seems to work fine, with the only downside I can see being a small bit of code duplication.
In essence each top-level scene plays its own music, and when switching scenes my scene manager fades out the music, along with the visuals.
The top-level scenes are essentially as follows:
- Menu: Plays its own music on repeat when it loads.
- Interstitial scenes: Each plays their own music, usually once through before moving to the next scene.
- Levels: Each plays music based on which “realm” they’re in, or whether it’s a boss-level. Additionally, when the player runs out of time the level switches to play “faster music”. And when the player dies, the level scene restarts the music.
The one advantage I can see with the per-scene music approach, is each type of scene can have their own unique interactions with the music (e.g. switching to faster music) without the other scene types being aware of those interactions.
To reduce code duplication I created a shared script file that handles fading etc, so the only real code duplication I have is some signal handlers that make calls to the script file.