我想在使用切换时保存声音状态,这样当我重新启动游戏时它就不会改变。我怎样才能做到这一点?请参阅下面的相关代码。
-(void)volumeItems {
// volume toggle
CCMenuItemImage *vON = [CCMenuItemImage itemWithNormalImage:@"volumeON.png" selectedImage:@"volumeOFF.png"];
CCMenuItemImage *vOFF = [CCMenuItemImage itemWithNormalImage:@"volumeOFF.png" selectedImage:@"volumeON.png"];
vToggle = [CCMenuItemToggle itemWithTarget:self selector:@selector(volumeSel:) items:vON , vOFF , nil];
.
.
.
}
-(void)volumeSel:(id)sender {
switch (vToggle.selectedIndex) {
case 0:
if (![[SettingsManager sharedSettingsManager] isVolON]) {
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"song.mp3"];
[[[SettingsManager sharedSettingsManager] setIsVolON:YES];
}
CCLOG(@"ON");
break;
case 1:
if ([[[SettingsManager sharedSettingsManager] isVolON]) {
[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
[[[SettingsManager sharedSettingsManager] setIsVolON:NO];
}
CCLOG(@"oFF");
break;
}
}