Let there be (another) sound
by Zilla · in Torque Game Builder · 08/03/2009 (7:48 am) · 7 replies
Is it possible to change the audio filename in the Audio Profile during the game or do I have to declare a seperate Audio Profile for every single sound?
for example:
Of course, this approach did not work because sound1 will always be played, but is there a way?
for example:
// game.cs
$audioFile = "~/data/audio/sound1.wav"
...
//audioDatablocks.cs
new AudioProfile(myAudioProfile)
{
filename = $audioFile;
description = "AudioNonLooping";
preload = true;
};
...
//somefile.cs
$audioFile = "~/data/audio/sound2.wav"
...Of course, this approach did not work because sound1 will always be played, but is there a way?
#2
Call it by using:
Note: Don't use numbers as file names or TGB will poop itself with an error and make sure $VOLUME is initialized to 1 for maximum and $SOUND is initialized to true. for volume control and turning sound off completely.
`Patrick
08/03/2009 (1:45 pm)
This seems to work for me, hope it helps.new AudioDescription(SE)
{
volume = 1.0;
isLooping = false;
isStreaming = false;
is3D = false;
type = $GuiAudioType;
};
function getAudio(%name, %type)
{
if (isObject(%name))
return;
new AudioProfile(%name)
{
filename = "~/data/audio/" @ %name @ ".wav";
description = %type;
preload = false;
};
}
function playSE(%sound, %volume)
{
// get profile for sound effect
getAudio(%sound, "SE");
if($SOUND)
{
// play sound
SE.volume = %volume;
$se = alxPlay(%sound);
}
}Call it by using:
playSE("nameOfWavFileWithoutExtension", $VOLUME);Note: Don't use numbers as file names or TGB will poop itself with an error and make sure $VOLUME is initialized to 1 for maximum and $SOUND is initialized to true. for volume control and turning sound off completely.
`Patrick
#3
Cool! Thank you:)
Is there also the possibility to unload "AudioProfile(%name1)" before you create a "new AudioProfile(%name2)"?
08/03/2009 (2:04 pm)
@PatrickCool! Thank you:)
Is there also the possibility to unload "AudioProfile(%name1)" before you create a "new AudioProfile(%name2)"?
#4
08/03/2009 (2:25 pm)
Sorry Zilla, I'm not sure. The game I use that code in is so lightweight, there's no need to optimize.
#5
It's a cool idea to create AudioProfiles on the fly when you need them.
You showed me some new and useful ideas. Thank you :)
08/04/2009 (1:30 pm)
@PatrickIt's a cool idea to create AudioProfiles on the fly when you need them.
You showed me some new and useful ideas. Thank you :)
Quote:The game I use that code in is so lightweight, there's no need to optimize.In my (iPhone) game/app I will have quite a lot of (small) audio files. Let's see how much memory they will eat..
#6
Always happy to help. I've been so busy at work that I haven't been able to work on any projects, so I'm trying to stay involved in the forums so I can at least do some torque script stuff.
I'm porting the game that uses that code to iPhone though so I'll be curious as to how it performs.
Patrick
08/05/2009 (8:08 am)
Thanks Zilla!Always happy to help. I've been so busy at work that I haven't been able to work on any projects, so I'm trying to stay involved in the forums so I can at least do some torque script stuff.
I'm porting the game that uses that code to iPhone though so I'll be curious as to how it performs.
Patrick
#7
08/07/2009 (2:09 am)
Quote:I'm porting the game that uses that code to iPhoneLooking forward to see your app :)
Torque Owner Zilla
How can I remove and then reload an AudioProfile?