Game Options GUI (Music,SoundFX, Full Screen)
by Stanley D Chatman · in Torque Game Builder · 09/08/2007 (8:29 am) · 7 replies
Does a tutorial or post exist that goes over the basics of creating a GUI screen that controls Music, SoundFX volume using GUI sliders and also a toggle button for muting music,sound and fullscreen mode.
I searched around and haven't ran across anything. Let me know if it exists.
I searched around and haven't ran across anything. Let me know if it exists.
#2
http://tdn.garagegames.com/wiki/GUI/
09/19/2007 (9:28 pm)
Not sure, but here's a page with some good GUI infohttp://tdn.garagegames.com/wiki/GUI/
#3
Just my opinion.
09/20/2007 (6:52 am)
Well, that is a good page as far as it goes, but it tells all the good things it is going to discuss, lists all the titles, then nothing. It would be a good doc if it came thru with what is lists.Just my opinion.
#4
5 global variables
$SoundVolume , $MusicVolume $SoundMute, $MusicMute , $FullScreen
GUI CallBack Code
Actuall GUI code
09/21/2007 (9:27 am)
I finally got a working solution and I am posting it here so that maybe others will find some use of it. I basically setup 5 global variables that I use to track the global state. I then made two functions playSound, playMusic that uses these global vars to set volume or mute. I basically wrap alxPlay.5 global variables
$SoundVolume , $MusicVolume $SoundMute, $MusicMute , $FullScreen
function playSound(%theSound)
{
%theSound.volume = $SoundVolume;
if ( $SoundMute == false )
{
%handle = alxPlay( %theSound );
}
return %handle;
}
function playMusic(%theMusic)
{
%theMusic.volume = $MusicVolume;
if ( $MusicMute == false )
{
%handle = alxPlay( %theMusic );
}
return %handle;
}GUI CallBack Code
function gameOptions::onDialogPush(%this)
{
guiMusicVolume.setValue( $MusicVolume );
guiSoundVolume.setValue( $SoundVolume );
guiMusicMute.setValue( $MusicMute );
guiSoundMute.setValue( $SoundMute );
guiFullScreen.setValue( $FullScreen );
}
function guiMusicVolume::onMouseDragged(%this)
{
echo("Dragging slider for Music Volume");
//alxSetChannelVolume( $menuloadmusic, %this.value );
alxSetChannelVolume( menuloadingAudio, %this.value );
$MusicVolume = %this.value;
}
function guiSoundVolume::onMouseDragged(%this)
{
echo("Dragging slider for Sound Volume");
$SoundVolume = %this.value;
}
function guiMusicMute::onClick(%this, %modifier, %worldPosition, %clicks)
{
echo("Music Mute Click");
$MusicMute = %this.getValue();
if ( $MusicMute )
{
alxStopAll();
}
else
{
playMusic( menuloadingAudio );
}
}
function guiSoundMute::onClick(%this, %modifier, %worldPosition, %clicks)
{
echo("Sound Mute Click");
$SoundMute = %this.getValue();
if ( $SoundMute )
{
//alxStopAll();
buttondownAudio.volume = 0;
rolloverAudio.volume = 0;
mainmenuclickAudio.volume = 0;
}
else
{
buttondownAudio.volume = $SoundVolume;
rolloverAudio.volume = $SoundVolume;
mainmenuclickAudio.volume = $SoundVolume;
}
}
function guiFullScreen::onClick(%this, %modifier, %worldPosition, %clicks)
{
echo("FullScreen Click");
$FullScreen = %this.value;
}Actuall GUI code
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(gameOptions) {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "0 0";
Extent = "800 600";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
new GuiBitmapCtrl(gameOptionsBack) {
canSaveDynamicFields = "0";
//internalName = "optionsBack";
isContainer = "0";
Profile = "GuiTransparentProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "203 94";
Extent = "394 394";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/options_back2.png";
wrap = "0";
new GuiBitmapButtonCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "myCustomProfile";
//Profile = "myCustomProfile";
HorizSizing = "right";
VertSizing = "bottom";
//Position = "461 427";
Position = "258 333";
Extent = "104 38";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
//Command = "Canvas.popDialog( gameOptions );";
Command = "unloadGameOptions();";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
bitmap = "~/data/images/btnOk";
};
new GuiCheckBoxCtrl(guiFullScreen) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiCheckBoxProfile";
HorizSizing = "right";
VertSizing = "bottom";
//Position = "235 425";
Position = "32 331";
Extent = "30 35";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
groupNum = "-1";
buttonType = "ToggleButton";
useMouseEvents = "0";
useInactiveState = "0";
};
new GuiCheckBoxCtrl(guiMusicMute) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiCheckBoxProfile";
HorizSizing = "right";
VertSizing = "bottom";
//Position = "345 254";
Position = "142 160";
Extent = "30 35";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
groupNum = "-1";
buttonType = "ToggleButton";
useMouseEvents = "0";
useInactiveState = "0";
};
new GuiCheckBoxCtrl(guiSoundMute) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiCheckBoxProfile";
HorizSizing = "right";
VertSizing = "bottom";
//Position = "345 378";
Position = "142 284";
Extent = "30 35";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
groupNum = "-1";
buttonType = "ToggleButton";
useMouseEvents = "0";
useInactiveState = "0";
};
new GuiSliderCtrl(guiMusicVolume) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiSliderProfile";
HorizSizing = "right";
VertSizing = "bottom";
//Position = "267 220";
Position = "64 126";
Extent = "250 33";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
range = "0.0 1.0";
ticks = "0";
//value = "0.5";
};
new GuiSliderCtrl(guiSoundVolume) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiSliderProfile";
HorizSizing = "right";
VertSizing = "bottom";
//Position = "267 337";
Position = "64 243";
Extent = "250 33";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
range = "0.0 1.0";
ticks = "0";
//value = "0.5";
};
};
};
//--- OBJECT WRITE END ---
#5
05/30/2008 (1:03 pm)
Thanks for the script you should place it in the TDN.
#6
05/30/2008 (7:00 pm)
You may want to save your settings in the $pref variable so they will all stay the same each time they run the game. As this code is written I believe the players will have to adjust the options each time they play.
#7
Here is that code:
05/30/2008 (7:11 pm)
That was just some of the code. I have functions that save the music,volume settingsHere is that code:
function saveVars()
{
$game_vars::current_user = $current_user;
$game_vars::all_users = $all_users;
$game_vars::GAME_OVER[$game_vars::current_user] = $GAME_OVER;
$game_vars::Score[$game_vars::current_user] = $score_text;
$game_vars::Health[$game_vars::current_user] = $health_score;
$game_vars::first_pickup[$game_vars::current_user] = $first_pickup;
$game_vars::first_pickup_health[$game_vars::current_user] = $first_pickup_health;
$game_vars::Level[$game_vars::current_user] = $cl;
$game_vars::Stage[$game_vars::current_user] = $cs;
$game_vars::wp[$game_vars::current_user] = $wp;
$game_vars::Bonus_Coins[$game_vars::current_user] = $bonus_score;
$game_vars::Trophy[$game_vars::current_user,1] = $trophy1;
$game_vars::Trophy[$game_vars::current_user,2] = $trophy2;
$game_vars::Trophy[$game_vars::current_user,3] = $trophy3;
$game_vars::Trophy[$game_vars::current_user,4] = $trophy4;
$game_vars::Trophy[$game_vars::current_user,5] = $trophy5;
$game_vars::Trophy[$game_vars::current_user,6] = $trophy6;
$game_vars::Trophy[$game_vars::current_user,7] = $trophy7;
$game_vars::Trophy[$game_vars::current_user,8] = $trophy8;
$game_vars::Trophy[$game_vars::current_user,9] = $trophy9;
$game_vars::Trophy[$game_vars::current_user,10] = $trophy10;
$game_vars::SoundVolume[$game_vars::current_user] = $SoundVolume;
$game_vars::MusicVolume[$game_vars::current_user] = $MusicVolume;
$game_vars::SoundMute[$game_vars::current_user] = $SoundMute;
$game_vars::MusicMute[$game_vars::current_user] = $MusicMute;
$game_vars::FullScreen[$game_vars::current_user] = $FullScreen;
// export these prefs to our optionsMenu prefs file
//export("$game_vars::*", "~/game/prefs/game_vars.cs");
export("$game_vars::*", "game_vars.cs");
//export("$game_vars::*",$PREFS_PATH);
}
function createDefaultPrefsFile()
{
%file = new FileObject();
%file.openForAppend("game_vars.cs");
//%file.openForAppend($PREFS_PATH);
%file.close();
initVars();
}
function loadVars()
{
// load all our "options" vars!
exec("game_vars.cs");
//exec($PREFS_PATH);
$score_text_OLD = "";
$cl_OLD = "";
$health_score_OLD = "";
$bonus_score_OLD = "";
$current_user =$game_vars::current_user;
$all_users = $game_vars::all_users;
$score_text = $game_vars::Score[$game_vars::current_user];
$health_score = $game_vars::Health[$game_vars::current_user];
$first_pickup = $game_vars::first_pickup[$game_vars::current_user];
$first_pickup_health = $game_vars::first_pickup_health[$game_vars::current_user];
$GAME_OVER = $game_vars::GAME_OVER[$game_vars::current_user];
$cl = $game_vars::Level[$game_vars::current_user];
$cs = $game_vars::Stage[$game_vars::current_user];
$wp = $game_vars::wp[$game_vars::current_user];
$bonus_score = $game_vars::Bonus_Coins[$game_vars::current_user];
$trophy1 = $game_vars::Trophy[$game_vars::current_user,1];
$trophy2 = $game_vars::Trophy[$game_vars::current_user,2];
$trophy3 = $game_vars::Trophy[$game_vars::current_user,3];
$trophy4 = $game_vars::Trophy[$game_vars::current_user,4];
$trophy5 = $game_vars::Trophy[$game_vars::current_user,5];
$trophy6 = $game_vars::Trophy[$game_vars::current_user,6];
$trophy7 = $game_vars::Trophy[$game_vars::current_user,7];
$trophy8 = $game_vars::Trophy[$game_vars::current_user,8];
$trophy9 = $game_vars::Trophy[$game_vars::current_user,9];
$trophy10 = $game_vars::Trophy[$game_vars::current_user,10];
$SoundVolume = $game_vars::SoundVolume[$game_vars::current_user];
$MusicVolume = $game_vars::MusicVolume[$game_vars::current_user];
$SoundMute = $game_vars::SoundMute[$game_vars::current_user];
$MusicMute = $game_vars::MusicMute[$game_vars::current_user];
$FullScreen = $game_vars::FullScreen[$game_vars::current_user];
updateGlobalVolume();
}
Torque Owner JD Scogin
Jd