Game Development Reference
In-Depth Information
We must also add a custom resource handler to allow WAV files to be loaded by the
resource manager. The following code snippet will do the trick:
IwGetResManager()->AddHandler(new CIwResHandlerWAV);
Finally, there is a manager class that takes care of all sound-related events and we
must ensure that we call the Update method of this class somewhere within the main
game loop. We do this with the following line of code:
IwGetSoundManager()->Update();
Loading and accessing sound resources
To load a WAV file all we have to do is add a reference to its filename into a GROUP
file, though we still need to do a little more in order to be able to play the sound
back. What we need to do is declare an instance of the class CIwSoundSpec .
This class allows us to reference a particular sound sample by name and lets us set a
volume and pitch to play the sound at. We can also specify whether or not we want
the sound to loop (note that SoundEngine currently provides no way of specifying
the number of times to loop the sound; we can only indicate continuous looping).
Here's an example definition:
CIwSoundSpec
{
name gun1
data gun_shot1
// Play at the default pitch for the sample
pitch 1.0
// Play at half volume
vol 0.5
// Do we want this sound to loop?
looping false
}
The pitch and vol (volume) parameters are specified as fractional scales, where
1.0 indicates the default pitch or volume level of a sound. We can also specify a
range for both these parameters that allows a random value to be chosen when
starting the sound. Specifying a range for the pitch can be quite useful to add a bit
of variety to the sound effects in your game without having to add lots of slightly
different sound samples.
 
Search WWH ::




Custom Search