Game Development Reference
In-Depth Information
_playingEffectSliderAudio = NO;
} delay:0.2f];
}
}
}
This will play a sound effect as an audio cue when moving the sound-effects volume
slider. The sound is prevented from repeating for 0.2 seconds to make it a little more
pleasing to the ears.
Without playing the sound effect, when dragging the sound-effects volume slider the play-
er wouldn't know how loud a given volume actually is. You don't have this problem with
music since the menu music is already playing and will adjust its volume when you drag
the music volume slider.
To actually change the volumes used by OALSimpleAudio 's effects and background
channels, you'll have to edit the GameState.m file. Locate the setMusicVolume and
setEffectsVolume methods, and add the highlighted lines of Listing 11-13 .
Listing 11-13 . Changing volumes
-(void) setMusicVolume:(CGFloat)volume
{
[OALSimpleAudio sharedInstance].bgVolume = volume;
[[NSUserDefaults standardUserDefaults] setDouble:volume
forKey:KeyForMusicVolume];
}
-(void) setEffectsVolume:(CGFloat)volume
{
[OALSimpleAudio sharedInstance].effectsVolume = volume;
[[NSUserDefaults standardUserDefaults] setDouble:volume
forKey:KeyForEffectsVolume];
}
The sound volume sliders are now functional. Feel free to try them out. Notice that the
volumes are not respected when starting the app, however. To fix that, add the highlighted
lines of Listing 11-14 to the sharedGameState method in GameState.m .
Listing 11-14 . Initializing volumes upon launching the app
Search WWH ::




Custom Search