Game Development Reference
In-Depth Information
Adjusting Audio Volumes
You probably remember that you've already created a Settings popover with volume
sliders. Now would be a good time to make them functional.
Open SettingsLayer.m in Xcode, and add the _playingEffectSliderAudio ivar
highlighted in Listing 11-11 .
Listing 11-11 . Adding another playback timing variable
@implementation SettingsLayer
{
__weak CCSlider* _musicSlider;
__weak CCSlider* _effectsSlider;
BOOL _playingEffectSliderAudio;
}
Then add the highlighted lines of Listing 11-12 to the volumeDidChange: method in
SettingsLayer.m .
Listing 11-12 . Playing a sound effect when moving the sound-effect slider
-(void) volumeDidChange:(CCSlider*)sender
{
if (sender == _musicSlider)
{
[GameState sharedGameState].musicVolume
= _musicSlider.sliderValue;
}
else if (sender == _effectsSlider)
{
[GameState sharedGameState].effectsVolume
= _effectsSlider.sliderValue;
if (_playingEffectSliderAudio == NO)
{
[[OALSimpleAudio sharedInstance]
playEffect:@"Audio/menu-sfx.caf"];
_playingEffectSliderAudio = YES;
[self scheduleBlock:^(CCTimer *timer) {
Search WWH ::




Custom Search