Adjusting Volume

When two ships crash in your game, do you want the sound to be an earthshattering roar? When players are talking behind enemy lines, should their voices be barely heard? You can easily adjust the volume of your sound effects by using the SoundVolume command in Blitz3D. You can even manipulate the volume of a sound so that it changes in relation to an object. For example, let’s say you have an object far off in the distance. You can have the sound get louder and louder as it approaches your player. Let’s start by adjusting the volume of a non-moving object and then get a bit fancier by adjusting the volume of a moving object.

Start by opening the file called demo12-02.bb. It is the same file we used in the last section that has a sphere that plays a sound when it bumps into a cube. To change the volume of a sound, you must enter a value for the volume between 0 and 1 (see Figure 12.1). Entering a value of 1 will produce the loudest sound, while entering 0 will produce no sound at all. You can enter any decimal value in between to adjust the volume level (for example, 0.3, 0.04, 0.9). In this example, we will make the volume half its current level by entering a value of 0.5.

Figure 12.1. You can adjust the volume “dial” from 0 to 1 for your sounds.


Take a look at the following code in bold from the existing code:

;Collision Sound
If CountCollisions (sphere)
PlaySound blaster
SoundVolume blaster, 0.5
EndIf

If you run the program now, you’ll notice that the volume level is half of what it was when we originally created the program. If we want to let the user change the volume, we could keep track of the volume with a variable and update Sound-Volume during each frame.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.124.21