Game Development Reference
In-Depth Information
LibGDX will silently ignore any requests to a referred sound if
that sound is no longer playing.
There are several overloaded methods to start playing a sound for a single time or in
an endless loop. Optionally, values for the sound's volume, pitch, and pan can also
be passed as shown here:
long play();
long play(float volume);
long play(float volume, float pitch, float pan);
long loop();
long loop(float volume);
long loop(float volume, float pitch, float pan);
The value for volume ranges between 0.0 and 1.0, where higher values result in
louder audio signals. Sounds can be pitched up and down resulting in lower or
higher frequency audio signals, respectively. A pitch value of 1.0 will play the sound
at its normal speed. Pitch values above 1.0 will let the sound play faster, while
values below 1.0 will result in slower playback. A pan value of 0.0 will play the
sound equally loud on the left and right audio channels, which is also referred to as
the center. Negative pan values will play the sound only on the left audio channel
whereas positive pan values will achieve the opposite.
Consider a scenario where we have two sounds, one for a cat and the other for a dog.
Both sounds will be loaded in LibGDX as separate sound instances that can be used
to play back several copies of them in parallel. To stop all playing copies of a (cat
or dog) sound instance, the stop() method can be called. Alternatively, a sound ID
can be passed to the stop() method to stop a specific copy of the (cat or dog) sound
instance only, as shown here:
void stop();
void stop(long soundId);
Sounds that are currently playing can be modified using their sound ID and one of
the following methods:
void setVolume(long soundId, float volume);
void setPan(long soundId, float pan, float volume);
void setPitch(long soundId, float pitch);
void setLooping(long soundId, boolean looping);
 
Search WWH ::




Custom Search