O'Reilly logo

Building Android Games with Cocos2d-x by Raydelto Hernandez

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

Modifying audio properties

You can easily modify the background music and the basic audio properties of the sound effect by calling the setBackgroundMusicVolume method and the setEffectsVolume method. Both receive a float value as a parameter, where 0.0 means mute and 1.0 means maximum volume, as the following code listing shows:

SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(0.5f);
SimpleAudioEngine::getInstance()->setEffectsVolume(1.0f);

Handling audio when leaving the game

When the game activity is no longer active, the background music and the sound effects will not stop automatically, they should be stopped manually by removing the following comment block from the applicationDidEnterBackgound method in the AppDelegate class:

// if ...

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