Just Simple Background Music in Mission
by TheHidden · in General Discussion · 04/12/2010 (8:50 am) · 2 replies
I have been trying for a week using several examples and notes but I can not seem to get music to play when a mission loads. I have tried a few posts on this site, but most I have referred on to the GUI. I have tried looking in the examples of the default FPS that comes with the install, but I have little faith in it since it does not even play the music.
I just have a simple mission in my own folder:
"C:\Programs\Torque\TGE_1_5_2\example\demo\dapper"
The mission is a simple and pretty much empty template:
"C:\Programs\Torque\TGE_1_5_2\example\demo\dapper\data\missions\lab005.mis"
Just a few basic things, learning to use program for class work. I wanted to add some Toby Mac (converted music file from MP3 to OGG) into the mission. Think it be nice for my project.
I have looked at a bunch of web pages as I stated but they point to GUI mainly, and I do not understand the code to figure it out easily (been a week). The ones not referring to the GUI, I just do not get what they are saying. Focused mainly on:
http://www.davidjsushil.com/index.php?action=tutorials/playingsounds.pdf
A bunch of posts in these boards and other sites.
Could someone please state what exactly has to be done, or the page that will show it exactly, to get a file to loop while a mission is loaded and ends when mission is closed.
Thanks for any help.
I just have a simple mission in my own folder:
"C:\Programs\Torque\TGE_1_5_2\example\demo\dapper"
The mission is a simple and pretty much empty template:
"C:\Programs\Torque\TGE_1_5_2\example\demo\dapper\data\missions\lab005.mis"
Just a few basic things, learning to use program for class work. I wanted to add some Toby Mac (converted music file from MP3 to OGG) into the mission. Think it be nice for my project.
I have looked at a bunch of web pages as I stated but they point to GUI mainly, and I do not understand the code to figure it out easily (been a week). The ones not referring to the GUI, I just do not get what they are saying. Focused mainly on:
http://www.davidjsushil.com/index.php?action=tutorials/playingsounds.pdf
A bunch of posts in these boards and other sites.
Could someone please state what exactly has to be done, or the page that will show it exactly, to get a file to loop while a mission is loaded and ends when mission is closed.
Thanks for any help.
About the author
This account has not been used since 2010, but no way to delete it. :/
#2
datablock AudioProfile(loop)
{
filename = "~/data/sound/amb.ogg";
description = "AudioDefaultLooping3d";
preload = false;
};
function PlayGui::onWake
{
$BGMHandle = alxPlay(loop);
}
It not work.
I went searching for any files in the Torque directory that have "BGMHandle" in it to see how they have it set up, but no .cs file in my install have that entry. So this is the way I put it all together in the one file right now.
Am I getting warm at all?
I already appreciate the help you offered, Scott.
04/12/2010 (6:51 pm)
This is what I figure you want me to do. I added in "\torque\TGE_1_5_2\example\demo\dapper\client\scripts\audioProfiles.cs":datablock AudioProfile(loop)
{
filename = "~/data/sound/amb.ogg";
description = "AudioDefaultLooping3d";
preload = false;
};
function PlayGui::onWake
{
$BGMHandle = alxPlay(loop);
}
It not work.
I went searching for any files in the Torque directory that have "BGMHandle" in it to see how they have it set up, but no .cs file in my install have that entry. So this is the way I put it all together in the one file right now.
Am I getting warm at all?
I already appreciate the help you offered, Scott.
Associate Scott Burns
GG Alumni
First you need to make sure you have an AudioProfile set up for your sound. Take a look at AudioProfiles.cs for the dummy takeme profile example. Clone that substituting the info for your music file and use AudioLooping2D for the description.
datablock AudioProfile(takeme) { filename = "~/data/sound/takeme.wav"; description = "AudioDefaultLooping3d"; preload = false; };To play the music you would use this call:
In this code we're calling alxPlay and passing it the audio profile that's been set up for the music file. The global variable catching the return value is slightly optional. If you want to be able to stop this specific file later without interfering with any other sounds playing then you'll need the handle alxPlay returns to do that. Otherwise you can just use alxStopAll() to stop all sounds currently playing.
Then it all comes down to when you want the music to start playing. If you want it during start up (the splash screens), then loadStartup is the place to call it. For main menu music you'd do it either in loadMainMenu or after it. For loading music you'd call it in loadMission, and for in-game level music you'd call it in PlayGui::onWake.
When the mission ends the music should stop playing automatically as there is a call to alxStopAll() in clientCmdMissionEnd().
Here's how to stop just the music itself:
Simply call alxStop and pass it the handle that alxPlay returned.
And that's the basics of playing background music, hope it helps.