Sunday, June 22, 2014

[libgdx] day 9 – sound & music

playing sounds or music is pretty easy in libgdx.
For testing this I downloaded two files from freesound.

silent-night.wav
page-turn.wav
I want the background music to play the whole time:
Music music;
//  [...]
music=Gdx.audio.newMusic(Gdx.files.internal("sound/silent-night.wav"));
music.setLooping(true);
music.play();
With music.setVolume(0.5f); you can change the volume of the music.ändern.
What pause() and stop() do, you can easily guess :D

Playing a sound is as easy:
Sound sound;
sound=Gdx.audio.newSound(Gdx.files.internal("sound/page-turn.wav"));
// [...] every time you want to play the sound.
sound.play();
To change the volume of a sound you have to pass it with play() (means play(0.5f))
There isn’t much more to say, except that you should again not forget to dispose everything:
music.dispose();
sound.dispose();
At the moment I do not have enough time to write detailed tutorials, but that will hopefully change in the next days.

No comments:

Post a Comment

Popular Posts