Level Select and Menu Music
by Lewis Bibby · in Torque 3D Professional · 08/20/2011 (12:48 am) · 7 replies
Hello there,
In my game I'm looking to split up the level select into different folders. So for example right now clicking play will take me to a level select that loads every .mis file in the level folder but I would like to change this so pushing play takes you to a world select which then in turn would then take you to a unique level select that would loads the levels from that worlds specific folder such as levels/Grassworld.
I'm also looking to add my own menu music to the game. If anyone could point me in the right direction for either of these issues then it would be much appreciated.
Thank you,
-Lewis
In my game I'm looking to split up the level select into different folders. So for example right now clicking play will take me to a level select that loads every .mis file in the level folder but I would like to change this so pushing play takes you to a world select which then in turn would then take you to a unique level select that would loads the levels from that worlds specific folder such as levels/Grassworld.
I'm also looking to add my own menu music to the game. If anyone could point me in the right direction for either of these issues then it would be much appreciated.
Thank you,
-Lewis
#2
"theme1" is a standard SFXprofile for "AudioMusic2D".
08/20/2011 (6:23 am)
function MainMenuGui::onWake(%this)
{
if (isFunction("getWebDeployment") &&
getWebDeployment() &&
isObject(%this-->ExitButton))
%this-->ExitButton.setVisible(false);
//yorks
$maintheme1=sfxCreateSource("theme1");
AudioChannelMusic.play();// make rocket go now!
$maintheme1.play();
echo("Start Main Menu Theme");
AudioChannelEffects.setVolume($pref::SFX::channelVolume2);
}
function MainMenuGui::onSleep(%this)
{
//yorks
$maintheme1.stop();
echo("Stop Main Menu Theme");
}"theme1" is a standard SFXprofile for "AudioMusic2D".
#3
08/20/2011 (6:27 am)
It occurred to me that the other item could perhaps be tickled into working if you add a "world" dropdown and use that to set a mask value. The mask value would match a new filename mask like "water" or "fire" or however you plan to break your worlds up, and then you save your mission files with that as part of the filename - for example, awesomeLevel.water.mis. Then you just populate the button strip using this file mask. You could use radio buttons or some other mutually exclusive collection UI element for the same purpose.
#4
As you can see, you can easily solve in various ways ;)
08/20/2011 (6:41 am)
I use this method:function MainMenuGui::onWake(%this)
{
....
//-------------------------------------
// BACKGROUND MUSIC
//-------------------------------------
if (!$handleMenuMusic)
$handleMenuMusic = sfxCreateSource(SFX_MenuMusicSound);
SFXPlay($handleMenuMusic);
....
}
function MainMenuGui::onSleep (%this)
{
....
//-------------------------------------
// BACKGROUND MUSIC
//-------------------------------------
if ($handleMenuMusic)
sfxStop($handleMenuMusic);
....
}As you can see, you can easily solve in various ways ;)
#5
08/20/2011 (6:47 am)
For the missions files, u can try this solution:function listMissionFiles()
{
%pattern = "art/*.mis";
%file = findFirstFile( %pattern );
if ( %file $= "" )
{
%file = findFirstFile( %pattern );
}
while( %file !$= "" )
{
// HERE YOUR CODE TO ADD ON THE SELECTION WINDOW ->
....
// <- HERE YOUR CODE TO ADD ON THE SELECTION WINDOW
%file = findNextFile( %pattern );
}
}
#6
08/20/2011 (9:31 am)
@Steve - HAH! Beat you by a minute! And thanks again for that, btw.
#7
Regarding the level split I occurred to me that for my menu system it might be better to drop the Array level load system that is currently in place and instead just assign buttons to load up specific levels myself. So any levels I haven't added to the menu myself would simply not appear except if I loaded then manually in the editor. Does anyone know how I could accomplish this?
08/20/2011 (4:15 pm)
Thanks for all your help. Main menu music is now in and rocking ^^Regarding the level split I occurred to me that for my menu system it might be better to drop the Array level load system that is currently in place and instead just assign buttons to load up specific levels myself. So any levels I haven't added to the menu myself would simply not appear except if I loaded then manually in the editor. Does anyone know how I could accomplish this?
Torque Owner Richard Ranft
Roostertail Games
Drop this at the end of your MainMenuGui.gui:
new SFXProfile(theme1) { filename = "art/sound/music/round_4.ogg"; description = "AudioMusicLoop2D"; preload = false; }; function MainMenuGui::onWake(%this) { if (isFunction("getWebDeployment") && getWebDeployment() && isObject(%this-->ExitButton)) %this-->ExitButton.setVisible(false); //yorks $maintheme1=sfxCreateSource("theme1"); AudioChannelMusic.play();// MAKE ROCKET GO NOW! $maintheme1.play(); echo("Start Main Menu Theme"); } function MainMenuGui::onSleep(%this) { AudioChannelMusic.stop(); }You can see from the comments that I left in here that Steve Acaster answered this question for me once and now I'm passing it on to you.
A few notes - the onWake() and onSleep() methods should overwrite the ones already there UNLESS you do something in yours that you want to keep. In that case, just add the audio related material to your version. Also, make the filename in the SFXProfile point to an actual file in your game.
Pass a "thank you" to Steve while you're at it... ;p