iosobjective-ccocos2d-iphonesimpleaudioengine

how to turn music and sound effects on/off in whole application from anywhere in COCOS2D?


I have 8 levels in my Game application. Each level screen has sound control button on top-right corner. When I click on that button it Toggles sound on/off.

If it is turned off in level one, it should be off in all levels. How can I do that?


Solution

  • If you use CocosDenshion to play your music, you can simply call

    [[SimpleAudioEngine sharedEngine] setBackgroundMusicVolume: value];
    [[SimpleAudioEngine sharedEngine] setEffectsVolume: value];
    

    value is float in range of 0..1