Game Development Reference
In-Depth Information
Persisting the Volume Slider Values
With the
GameState
class in place, you can now connect the sliders with the two
volume properties in the
GameState
singleton to persist their values.
Add the lines highlighted in
Listing 7-14
to
SettingsLayer.m
.
Listing 7-14
.
Connecting the slider values with GameState properties
#import "SettingsLayer.h"
#import "MainMenuButtons.h"
#import "GameState.h"
@implementation SettingsLayer
{
__weak CCSlider* _musicSlider;
__weak CCSlider* _effectsSlider;
}
-(void) didLoadFromCCB
{
GameState* gameState = [GameState sharedGameState];
_musicSlider.sliderValue = gameState.musicVolume;
_effectsSlider.sliderValue = gameState.effectsVolume;
}
-(void) volumeDidChange:(CCSlider*)sender
{
if (sender == _musicSlider)
{
[GameState sharedGameState].musicVolume
= _musicSlider.sliderValue;
}
else if (sender == _effectsSlider)
{
[GameState sharedGameState].effectsVolume
= _effectsSlider.sliderValue;
}
}
-(void) shouldClose
{
[[NSUserDefaults standardUserDefaults] synchronize];
Search WWH ::
Custom Search