Game Development Community

Playing music throughout the main menu

by Braveheart · in Torque Game Engine · 03/08/2008 (2:32 pm) · 3 replies

Hello all,

I've been trying to get music to play in the background of my main menu. But I have had no avail so far. So I've came here for some help and advice, I'm a total beginner in Torque Script just for the record :p.

Anyway, how would I go about getting a music file (.wav) to play throughout my main menu?

#1
03/08/2008 (4:06 pm)
In your client scripts there will be an audioProfiles.cs file. First you will need a new channel assignment.
$MusicAudioType = 4; // this will be your channel type for music

Next comes the AudioDescription followed by an AudioProfile
new AudioDescription(MusicLooping)
{
	volume = 2.0;
	isLooping= true; 
	is3D = false;
	type = $MusicAudioType;
};

new AudioProfile(menuMusic)
{
	filename = "~/data/sound/music/Vortex.ogg"; //can be either .wav or .ogg files
	description = "MusicLooping";
	preload = true;
};

Find your mainMenuGui.gui and at the end add:
function mainMenuGui::onWake(%this) 
{
	if (!alxIsPlaying($musicHandle)) // if music is not already playing then play it
		$musicHandle = alxPlay(menuMusic);
}
This will make the menuMusic play when the main menui pops up. To make it stop when you load a mission you'll need to modify the mission.cs script in the common/client directory. Find the function clientCmdMissionStart(%seq) - should be at the top
function clientCmdMissionStart(%seq)
{
	alxStop($musicHandle); // stop the mainmenu music
}
That should give you music in your main menu. I'm pretty sure this exists as a tutorial on the Torque Developer Network. I hope I didn't forget anything and good luck!
#2
03/09/2008 (5:38 pm)
Thanks for the reply! But unfortunately that didn't work for me... But, I did find a tutorial on TDN which worked finally.

One thing, why doesn't the "Volume" in the description really change the volume? How can I get the music to play louder? I changed it from 2.0 to 9.0, there was no change what so ever.
#3
03/11/2008 (3:51 pm)
Was it the channel assignment? The tutorial on TDN was what I started with, and it uses a value of 3, you would have to change this for different projects. I added a line to the mainMenuGui::onWake function to prevent the music from "stacking" if you back out of the mission load screen or the options screen. You might want to check that, the rest of the code is the same as the TDN article

I believe that volume is a range between 0.0 - 1.0 with 1.0 being the max volume. I didn't actually notice I had it set to 2, but then the TDN page has it also. You can raise the volume in the in-game sound options. I think you would have to make a new slider for music adjustments only though.