Game Development Community

Add background music to main menu (Torque 3D)

by Brian Westgate · in Technical Issues · 01/31/2011 (1:58 am) · 12 replies

I've searched through the resources available and it appears everyone in the world has solved this problem besides me. Most, add background music resources for torque 3D are adding music to the actual game world. I am only looking to add a looping background sound/music file to the mainMenuGui. I've actually taken a simple approach to make sounds in the game world
sfxPlayOnce(Audio2D,"art/sound/orc_pain","0 0 0");
. I don't use many 3D sounds in my game. For some reason this doesn't work at the main menu page I can only assume it is because certain devices haven't been registered yet, or something to that effect. I've gotten it to work on the loading screen after selecting a mission to play, but that isn't what I'm looking for. I am only using the demo version of Torque 3D so I cannot edit any hard code. Is there a scripting solution (without additional software) for adding a looping sound/music file to the mainMenuGui? Thanks
Brian



#1
01/31/2011 (3:14 am)
That's a problem I have caused with setting up sound differently for when games start and stop to cause sounds to play when a level is actually started and not while it is still loading. I will rectify this problem in 1.1 final.

What's happening is that the music audio group has its playback stopped while not in a game and thus the sounds you are initiating are stopped as well.

Either put your sounds in a different sound group or start playback of the audio music group with

AudioChannelMusic.start();

//PS: Please be aware that you need a valid T3D license in order to develop games with the beta3 version of T3D that you are employing here.
#2
02/01/2011 (4:26 am)
Don't worry Rene, I am only using this engine for my senior project at DeVry University. I have no intention of creating a game for retail with this engine.

Now what do you mean sound groups? Are you referring to sims? I only use this line of code to perform all my audio sounds.

sfxPlayOnce(Audio2D,"art/sound/orc_pain","0 0 0");

How would I go about employing ?
AudioChannelMusic.start();

I haven't created SFXProfile, or SFXDescriptions for any of my audio because the code above takes that information as a argument. If I have to created profiles, etc how do I load them to be played by AudioChannelMusic.start()? Does it simply search for profiles & descriptions of a certain type? Also how would I be able to get the music to play in the background of mainMenuGui? I am really not familiar with torque audio at all so sorry for all the questions.
Brian
#3
02/01/2011 (4:54 am)
Quote:Now what do you mean sound groups?

Sounds in T3D 1.1 are arranged in hierarchical sound groups. At the top is the master source and then below it a number of sources for the different areas of game sounds. If playback of a given source is stopped, all sources underneath it stop too.

These groups are instances of SFXSource, i.e. they have all the playback controls but are not tied to audio data themselves.

Quote:How would I go about employing ?

One way is to just put the call right in front of your sfxPlayOnce() call. All that matters is that to get the music to play, you need to call start() on the AudioChannelMusic SFXSource object.

For 1.1 final, I'll take the music group out of the start/stop sequence and let only the sound effects group do that. It's important to be aware though that this is just a setup in the stock scripts and nothing inherent in the audio system. If someone wants to have it work differently, all he/she has to do is set up custom sound groups.
#4
02/01/2011 (5:24 am)
Looking at your call to sfxPlayOnce... you can avoid to pass in the position ("0 0 0"), since you pass to the function a profile that is 2d (Audio2D)...

Audio2D is a sfxDescription, defined into
gamecorescriptsclientaudioDescriptions.cs
and inherits from the "AudioEffects" sfxDescription define into
gamecorescriptsclientaudio.cs

singleton SFXDescription( AudioEffect )
{
   volume         = 1.0;
   sourceGroup    = AudioChannelEffects;

So it seems to me that you has to use instead
AudioChannelEffects.start();

... in fact both those channels are defaulted as stopped, above in the same file (gamecorescriptsclientaudio.cs)
// Set default playback states of the channels.

AudioChannelMaster.play();
AudioChannelDefault.play();

AudioChannelGui.play();
AudioChannelMessages.play();

// Stop in-game channels.
AudioChannelEffects.stop();
AudioChannelMusic.stop();

@ Rene: am I right or I'm not considering something?
#5
02/01/2011 (6:26 am)

Yep, good catch Giorgio. I was implicitly assuming Brian was using some of music-specific profiles and didn't actually look.

So yep, both the effects and music group are stopped and thus, if you use the effects group instead of the music group, then it all applies to AudioChannelEffects instead. Only that I will leave that as it is. AudioChannelEffects is for in-game sound effects.
#6
02/01/2011 (6:46 am)
Ok, so Brian I suggest you to use AudioMusicLoop2D or AudioMusic2D...

Obviously the difference is that the 1st has looping enabled (and also streaming) that appear to be something you want... both are played into AudioChannelMusic so your music would start even at gui screen before to be in game...

So use:
sfxPlayOnce(AudioMusicLoop2D,"art/sound/orc_pain");

@ Rene: if he wants this music only playing into main gui and not in game where has he to stop it?
#7
02/01/2011 (6:52 am)

Quote:@ Rene: if he wants this music only playing into main gui and not in game where has he to stop it?

There's no support per se for doing that but you can easily key the transition on when playGui comes up, i.e. use playGui's onWake() to fade out the main menu music and fade in the level's background music.
#8
02/01/2011 (7:22 am)
Tnx Rene, me too interested in this, so I'll take a look into it :-)
#9
02/01/2011 (7:28 am)
I've made the changes Gio you suggested. I guess I forgot to remove the position coords when I switched to 2D audio. Thanks also Rene.
#10
01/08/2012 (9:07 pm)
Hi all

I realise this is an old thread but ive been using the above method to trigger menu music in my project. it works great but im having trouble stopping the music, hopefully someone can help ;)

im triggering the music with this line in the onwake func
sfxPlayOnce(AudioMusicLoop2D," my/music/file ");

when i try sfxstop it doesnt work but the console advises that this is the same as

sfxSource::stop (AudioMusicLoop2D);

when i try that it crashes out !!

any help much appreciated.





#11
01/09/2012 (7:20 am)
I think SFX has gone through a few changes in 1.2, so your best bet is to look through the cs files to see how audio is started. (I'd suggest startnig with init.cs and trace through the loading process)
#12
01/09/2012 (11:12 am)
hi steve ;)

thanks for the help after digging around in the guimusicplayer i realised i need a head slap

problem was i didnt create the sfx objecty thingy to call stop on

so heres whats working for me now

ive added this to the mainmenu onwake

%this.sfxSource = sfxPlayOnce (GuiMusicPlayerLoopingStream, "my / music / file ");

and this to the onsleep

%this.sfxSource.stop( 0 );

works ok so far .. woot