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...