Skip to Main Content
Learning iPhone Game Development with Cocos2D 3.0
book

Learning iPhone Game Development with Cocos2D 3.0

by Kirill Muzykov
June 2014
Beginner to intermediate content levelBeginner to intermediate
434 pages
9h 49m
English
Packt Publishing
Content preview from Learning iPhone Game Development with Cocos2D 3.0

Time for action – storing settings in NSUserDefaults

Right now, the audio settings are not saved across the game launches because we only save them in instance variables in memory. To fix this, we're going to save them in NSUserDefaults and load them when the game starts, as follows:

  1. Open the AudioManager.m file and add the following #define statements to define the keys we'll use to save and load the corresponding audio setting:
    #define kSoundKey @"AudioManager_Sound"
    #define kMusicKey @"AudioManager_Music"
  2. Scroll down to the toggleSound method and add the code to save the sound setting at the end of the method, right after it's changed:
    -(void)toggleSound
    {
        _isSoundEnabled = !_isSoundEnabled;
        
        [[NSUserDefaults standardUserDefaults]
     setBool:_isSoundEnabled ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

James Goodwill, Wesley Matlock

Publisher Resources

ISBN: 9781782160144Supplemental Content