Creating sound effects. example onCollision?
by Karl Jahnke · in Torque Game Builder · 10/11/2007 (10:21 am) · 2 replies
I just can not seem to wrap my head around the creating sound effects on an event. I don't really understand Datablocks all that much either and all the tutorials seem to call for sounds thru a datablock.
What i am hoping for is to create a sound effect similar to creating new sprites. i.e. :
%sprite = new t2dImageMap
{
2dSceneWindow = %this.scenegraph
}
Thanks for any help you can offer. I am slowly getting the hang of this scripting stuff, but its all new to me.
What i am hoping for is to create a sound effect similar to creating new sprites. i.e. :
%sprite = new t2dImageMap
{
2dSceneWindow = %this.scenegraph
}
Thanks for any help you can offer. I am slowly getting the hang of this scripting stuff, but its all new to me.
#2
10/12/2007 (8:00 pm)
Thank you for the help! And you accually helped me gett a little better understanding of the datablock thing too. =)
Torque Owner Dmitriy Stukalov
Probably it is very hard for you to understand sounds because you are artist (not a programer).
Well, create the file sound.cs. Put into the file the code below.
//Non looping sound datablock new AudioDescription(SoundNonLooping) { volume = 1.0; isLooping = false; is3D = false; type = $GuiAudioType; }; // Looping sound datablock (for music or ambient sounds) new AudioDescription(SoundLooping) { volume = 1.0; isLooping = true; is3D = false; type = $GuiAudioType; }; // This function will load nonlooping sound from file and set the sound name to use in your game function loadNonLoopingSound(%sound_name, %file_name) { new AudioProfile(%sound_name) { filename = %file_name; description = "SoundNonLooping"; preload = true; }; } // This function will load looping sound from file and set the sound name to use in your game function loadLoopingSound(%sound_name, %file_name) { new AudioProfile(%sound_name) { filename = %file_name; description = "SoundLooping"; preload = true; }; } // In this place you will insert the path to your sounds and it names loadNonLoopingSound("MyCoolSound1", "MyCoolGame/data/audio/gui/my_cool_sound_1.wav"); loadNonLoopingSound("MyCoolSound2", "MyCoolGame/data/audio/gui/my_cool_sound_2.wav"); ... loadLoopingSound("MyCoolMusic", "MyCoolGame/data/audio/gui/my_cool_music.wav"); ...Add to your game.cs the line below
exec("./sound.cs");Now you are able to start your sounds from any place of your game!
For nonlooping sounds:
alxPlay("MyCoolSound1");For looping souns:
$music = alxPlay("MyCoolMusic"); ... alxStop($music);Best regards!
EDIT: Close bracket for code area :)