O'Reilly logo

Cocos2d-x Game Development Essentials by Gareth Jones, Arutosh Gurung, Frahaan Hussain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding sound effects

There will be two main sound effects that will be played throughout the game:

  • Button-click sound effect: This will be played whenever a menu button is clicked excluding the pause button
  • Crash sound effect: This will be played when the player's space pod collides with an asteroid

Adding the menu-button-click sound effect

Let's add the menu-button-click sound effect in the MainMenuScene.cpp file using the code explained in the following steps, which follows the steps given in the Loading and playing sound effects section:

  1. Add the sound header to the top of the file:
    #include "SimpleAudioEngine.h"

    This is how the MainMenuScene.cpp file will look after adding the preceding header file:

  2. Preload the sound effect inside the init() method ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required