4. Sound

While graphics create a games world, sound and music create its atmosphere. This chapter deals with how to load, play and handle both.



4.1 The Basics

ZweiDe's Sound system basically consists of two classes: Sound and SoundEmitter. The first one loads and stores sound data while the second ones job is to create and keep track of currently playing sound sources.

As playing and handling sounds is not that hard, all we need to do in this chapter is understanding the basic methods and properties. Let's start with an easy example:

ZweiDe.Sound sfx = ZweiDe.Sound.Load("somesound.wav");
...
ZweiDe.Sound.Play(sfx);

And there you go. This is the basic code playing a sound effect; but we can expand both loading and playing in order to reveal more configuration options:

ZweiDe.Sound sfx = ZweiDe.Sound.Load("somesound.wav", preLoad);

If preLoad is set to false (it defaults to true), Sound.Load does not actually load the sound but schedules it for loading it as soon as it is neccessary (using a stream if possible). This is useful when loading music or big sound files that shouldn't rest in memory not leaving space for other ones. It is not recommended for sound effects e.g. small sounds that are played very frequently.

ZweiDe.SoundEmitter sfxEmit = ZweiDe.Sound.Play(sfx, looped, startPaused, enableFx);

When setting looped to true, the sound never stops playing unless you stop it by calling sfxEmit.Stop.
Using startPaused it is possible to set some additional emitter values (volume, pan, playback speed, ...) before playing the sound.
EnableFx has to be true whenever it is intended to add dynamic sound effects (echo, distortion, ...) to the sound source. This will be explained in the next chapter.



4.2 '3D' sound and effects

Coming soon!





Proceed to the next page -->