42 videos
238 minutes
Let's see how to add music and sounds to the game. It is very easy to do actually. Because we have a class, actually two, in libgdx, they used to work with sounds and music. They are Sound, and Music. And what I've done here is add in the assets folder files that I use. I'll add a song, I've made OGG to weigh less. And two sounds that are in OGG but who may be in WAV or MP3: jumping sound, and the sound of death.
I will add them to assetManager, by calls to load () to load for die.ogg side, a Sound. And as another Sound jump.ogg. Finally song.ogg as Music. Cargo files, classes charge. And I have it ready. This will make the game open late, admittedly. So then I'll do the loading screen. Now what I have to do is, you can play where appropriate. For example, let's see how to play in
First sounds. And for that I'm going to do is, when I start my game to get the jump sound, and the sound of death. And I will make sounds Manager removing them prepare. Both jump.ogg as die.ogg. Now what I'm going to do is ... in fact, out of act () the justTouched, and I will move the GameScreen. To ask the player to start his jump. Thanks to this, I can now play the sound from
here without complicate the class structure. It is a change very last time. To play a sound, like the sound jumping, all you have to do it is to use the play (method), which is reproduced below. We can change the volume, tone, or if we move it to the left or right stereo speakers. I call play (), and reproduces. Let it play when you start a jump like when you do a double jump. And finally, if you lose you do
sound when you lose. And now, as I think I have not set the dual sound on my PC I will butt up the volume so you can listen to the sounds. [Poing] [Pss] Okay. If possible not at once, but you know I'm bad playing. [Poing] [Poing] [Pss] Good. I have already said it will not I'm good at these games. It remains to play music. I draw the Manager, and keep in bgMusic. The sack as song.ogg. I'll do that in the show (),
When the game begins, one of the first things you do is start playing music. So it is not very annoying, what I do is which is set as 75% volume, so you may not play so hard, and I'm going to play. And in the hide (), rather than play it, I'll call stop () to stop ringing. Now when the game starts ... [Music] [Poing] [Pss] It occurs to me that why not do the music stops when you die,
as in the original game. With how well the game will last no music. [Music] [Poings] [Pss] With this playing music. multiple is heard. You should check if the player is already dead not to play again. It should no longer sound so often noise. Pilláis the concept. always call play () to start playback, or stop () to stop playback. With this you can play sound effects and music.
You might think that just no difference between Sound and Music. The sound is full load. The music tries bufferizarse not occupy much space. Further, sounds and music are by different audio channels on the sound card so you can you can play multiple sounds at once but it you just can not play several songs. This is all about sounds and music. We will continue to refine the final details of the game.
About the Author
Biography: Analyst-Programmer in different languages. Tutor PREMIUM platforms recognized worldwide as CodigoFacilito. Editor Cristalab articles. My YouTube Channel is sponsored by the ANAYA and LaTostadora publisher. I like to explain in detail and give several examples for the avoidance of doubt.