Viewers: in countries Watching now:
Discover how to build an Android game and distribute it in the Google Play app store, using Cocos2d-x and the Eclipse Platform. Plus, author Todd Perkins shows how to monetize your game further with income from Google Mobile ads. The course demonstrates how to install and set up your coding environment; build the game's core scenes, layers, and sprites; handle touch and accelerometer data; create classes based on a detailed game flow chart; and manage misses, wins, and scores. Last, you'll prepare your game to support Google ads and in-app purchases.
Sound effects and music will give more life to your game. To do that, we are going to use simple audio engine. If you go to the MainMenu class, you will see that I already have a few lines of code where I used simple audio engine. You can access the singleton instance through sharedEngine and you can run simple methods like stopBackgroundMusic, preloadBackgroundMusic, playBackgroundMusic, preloadEffect and playEffect. I am going to copy this preloadEffect line of code and just paste it on the next line. I am also going to preload moles_miss.wav.
Save this file and go over to Game.cpp. In initializeGame(), I am going to play the background music. So it's SimpleAudioEngine and make sure that you include this class if you haven't already, sharedEngine()-> playBackgroundMusic and the BackgroundMusic is going to be moles_bg.mp3. I use mp3 files for background music to conserve file size and WAV files for effects to preserve quality. And that's because the effects are always very, very short, so an mp3 doesn't save a ton of space in a half second.
Let's scroll down and we are going to find the TouchesBegan method and where the mole->wasTapped and we didScore, I am going to play the Splat effect. So SimpleAudioEngine:sharedEngine()-> playEffect and the effect is going to be SOUND_SPLAT. Save the file and then we'll go over to the HUD.cpp and when we miss a mole, which we handle in missedMole, near the top I am going to play the miss sound.
So I will paste that code that I copied earlier to preload the Effect. I will change it to playEffect. Change SOUND_SPLAT to the string, moles_miss.wav and that's it. So now we should build the save and run the app in the emulator and once it launches we will hear that background music play as we play the game, the miss sound, when you miss a mole, and the hit sound when you tap a mole. So we hit the Play button and we should hear the sound. (music playing) So I will close the emulator and you could hear the background music playing as I play the game and when I tapped a mole, it played the splat sound, and when I missed a mole it played the missed sound.
So you can use sound effects using Simple Audio Engine and the simple methods like play effect and preload effect.
There are currently no FAQs about Building and Monetizing Game Apps for Android.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.