ios - Save state of the options settings (cocos2d) -


i've question, want game save state of settings in options scene, example..if switch off music clicking on music button, music off , written under music image "music off" if change scene ,the settings remain same set , until here ok....but when restart application, settings returning before, music on , "music on" in written under music image, how can fix this?

the easiest , common way achieve nsuserdefaults.

firstly, have register defaults @ first launch (in applicationdidfinishlaunch).

 nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults]; if (![userdefaults boolforkey:@"haslaunchedonce"]) {             [userdefaults setbool:yes forkey:@"haslaunchedonce"];             nsdictionary* defaults = [nsdictionary dictionary];             [defaults setvalue:@yes forkey:@"musicon"];             [userdefaults registerdefaults:defaults];     } 

then example set new value on button press

musicbutton.block = ^(id sender) {         nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults]; [userdefaults setbool:yes forkey: @"musicon"]; // [userdefaults synchronize]; // dont need force everytime, if want      }; 

and if want check anywhere in code if music on do

  nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults];  if ( [userdefaults boolforkey:@"musicon"] ) { /* */} 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -