Creating a simple soundscape

verSoundscape is a component in Verlocity that manages the playing a sound or combination of sounds that form an environment.

This tutorial shows how to set up and play a soundscape.

Step 1
Create a new blank class file in 'Game/soundscapes/'. If the soundscapes folder doesn't exist, create it. The name of the class will be the name of your soundscape. Be descriptive!

Step 2
In order to have the correct packages available to us, we need to import them. Within the first pair of brackets, type: import VerlocityEngine.base.sound.verBSoundGroup; import VerlocityEngine.base.sound.verBSoundGroupSettings; import VerlocityEngine.base.sound.verBSoundscape;

Step 3
For the soundscape to function correctly, it must extend from verBSoundscape. public class Soundscape_CityWar extends verBSoundscape { }

Step 4
Now for the fun part. In the constructor function for your soundscape, (in my case it is Soundscape_CityWar) type in the following. var sgBackgroundNoise:verBSoundGroup = new verBSoundGroup( "content/sounds/shoot", 4 ); var sgSettings:verBSoundGroupSettings = new verBSoundGroupSettings( 6000, 1500, 0.35, 0.2, 105, 95, false ) These variables require some explanation.


 * On the first line we are creating a new verBSoundGroup object. This object tells the manager all the available sound files it can use. The first argument is the directory to the sound files, and the first part of their name. The second argument is the number of files. So for example this code will look for the following files:

content/sound/ shoot01.mp3 shoot02.mp3 shoot03.mp3 shoot04.mp3

All go in the 'sounds' folder of the 'content' folder.


 * The second variable stores the settings for that group of sounds. First is the maximum time it takes for a sound to be played, then the minimum. Then the maximum volume (ranged from 0-1), then the minimum volume. Then the maximum pitch and the minimum pitch. And finally the boolean telling whether the sounds should loop or not.

Step 5
Finally we need to add this group to the global list of soundscapes. To do so: AddSoundGroup( sgBackgroundNoise, sgSettings ); 'sgBackgroundNoise' contains the sound group we created above. And of course 'sgSettings' is all the settings related to the sound group.

Step 6
Your finished code should look something like this: package Game.soundscapes {	import VerlocityEngine.base.sound.verBSoundGroup; import VerlocityEngine.base.sound.verBSoundGroupSettings; import VerlocityEngine.base.sound.verBSoundscape;

public class Soundscape_CityWar extends verBSoundscape {		public function Soundscape_CityWar:void {			var sgBackgroundNoise:verBSoundGroup = new verBSoundGroup( "content/sounds/shoot", 13 ); var sgSettings:verBSoundGroupSettings = new verBSoundGroupSettings( 6000, 1500, 0.35, 0.2, 105, 95, false ) AddSoundGroup( sgBackgroundNoise, sgSettings ); }			} }

Step 7
You're almost ready to compile. To use the soundscape, you just need to set it. You can place this anywhere in your code as long as you import Verlocity. import VerlocityEngine.Verlocity;

Verlocity.soundscape.Set( new Soundscape_CityWar); Viola! Listen closely and you should be hearing your scene come to life! To stop it, simply either Set a new soundscape or Stop it.

In conclusion
Soundscapes can add quite a lot to your game's environment and are highly useful for creating excellent sound design.

If you want to learn more about the some more practices of sound design, follow the next article: Executing great sound design.