Book Image

Building Android Games with Cocos2d-x

By : Raydelto Hernandez
Book Image

Building Android Games with Cocos2d-x

By: Raydelto Hernandez

Overview of this book

Table of Contents (16 chapters)
Building Android Games with Cocos2d-x
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 you use SimpleAudioEngine, it must be pause
 SimpleAudioEngine::getInstance()->pauseBackgroundMusic();

In order to make this new line of code work, we need to add the same line that we have added to the HelloWorld.cpp implementation file in...