Building and Monetizing Game Apps for Android
Illustration by Don Barnett

Adding sound


From:

Building and Monetizing Game Apps for Android

with Todd Perkins

Video: Adding sound

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.
Expand all | Collapse all
  1. 5m 1s
    1. Welcome
      59s
    2. Using the exercise files
      2m 36s
    3. What you should know before starting this course
      25s
    4. Viewing the finished game
      1m 1s
  2. 19m 49s
    1. Understanding and downloading Cocos2d-x
      2m 16s
    2. Downloading the Android NDK
      1m 49s
    3. Creating a Cocos2d-x project template for Eclipse
      4m 51s
    4. Finishing the project template
      1m 4s
    5. Preparing Eclipse to use C++
      1m 9s
    6. Importing the project into Eclipse
      3m 48s
    7. Adding GLES 2.0 support to your emulator
      3m 45s
    8. Fixing additional compiler issues
      1m 7s
  3. 52m 7s
    1. Understanding scenes, layers, and sprites
      2m 16s
    2. Using scenes, layers, and sprites
      3m 58s
    3. Positioning sprites
      1m 4s
    4. Adjusting basic sprite properties
      5m 32s
    5. Handling touches
      3m 54s
    6. Accessing accelerometer data
      6m 7s
    7. Understanding Cocos2d actions
      2m 37s
    8. Working with sprite sheets
      4m 28s
    9. Creating simple frame animations
      3m 44s
    10. Setting a game to display in portrait mode
      54s
    11. Designing for multiple screens
      3m 20s
    12. Running Java code from C++
      5m 21s
    13. Running C++ code from Java
      3m 31s
    14. Using buttons
      3m 34s
    15. Playing audio
      1m 47s
  4. 17m 0s
    1. Viewing a flowchart of the game's core classes
      1m 25s
    2. Creating constants and editing the AppDelegate and Main classes
      4m 8s
    3. Building the GameButton class
      3m 38s
    4. Constructing the custom pop-up menu utility
      2m 52s
    5. Setting up the code in the MainMenu class
      2m 10s
    6. Making the Utils class
      2m 47s
  5. 53m 13s
    1. Adding the game layers and the background
      5m 41s
    2. Laying out moles in the Game class
      4m 45s
    3. Animating the moles
      5m 44s
    4. Displaying moles at a specified time interval
      4m 39s
    5. Handling touches in the game
      4m 11s
    6. Displaying the player's score
      4m 2s
    7. Handling misses
      6m 27s
    8. Controlling the number of moles on the screen
      2m 25s
    9. Adding sound
      2m 31s
    10. Enabling a pause feature
      5m 36s
    11. Displaying the game-over screen
      3m 13s
    12. Saving the player's high score
      3m 59s
  6. 6m 53s
    1. Preparing your game to support Google ads
      3m 14s
    2. Implementing Google ads in your game
      3m 39s
  7. 18m 9s
    1. Handling skins in your game code
      4m 55s
    2. Setting up in-app purchases (IAP) for an Amazon Appstore app
      3m 1s
    3. Implementing Amazon IAP code
      4m 11s
    4. Setting up IAP for Google Play
      2m 38s
    5. Implementing Google Play IAP code
      3m 24s
  8. 2m 56s
    1. Using the Cocos2d-x website
      1m 13s
    2. Viewing additional Android game development resources
      1m 43s
  9. 29s
    1. Goodbye
      29s

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course Building and Monetizing Game Apps for Android
2h 55m Intermediate Mar 22, 2013

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.

Topics include:
  • Installing and downloading Cocos2d-x
  • Positioning sprites and adjusting their properties
  • Creating simple frame animations
  • Designing for multiple screen sizes
  • Adding buttons
  • Incorporating audio
  • Creating the core classes and constants
  • Adding the game layers and background
  • Displaying challenges at timed intervals
  • Displaying the player's score
  • Enabling a pause feature
  • Enabling ads and in-game purchases for Google Play and the Amazon Appstore for Android
Subject:
Developer
Software:
Android Cocos2d
Author:
Todd Perkins

Adding sound

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.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Building and Monetizing Game Apps for Android.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.