how can I store the current status of the game in cocos2d ?
        Posted  
        
            by srikanth rongali
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by srikanth rongali
        
        
        
        Published on 2010-05-12T10:07:44Z
        Indexed on 
            2010/05/12
            10:14 UTC
        
        
        Read the original article
        Hit count: 231
        
I am writing a shooting game in cocos2d. And each enemy enters the screen after the current one is dead. I have stores the enemies and their properties in plist. I need to save the current state of the game. If any phone call comes the game should be started from the current state.
So, I usedNsUserDefaults in this way,
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
   ...
   NSUserDefaults *myDefaultOptions = [[myDefaultOptions stringForKey:@"enemyNumber"]intValue] ;
//tempCount4 is the current Enemy number. It was declared in another class. I am using extern and using the value here.
  tempCount4 = [[myDefaultOptions stringForKey:@"enemyNumber"]intValue] ;
}
- (void)applicationWillTerminate:(UIApplication *)application {
    [[CCDirector sharedDirector] end];
    [myDefaultOptions setObject:tempCount4 forKey:@"enemyNumber"];
}  
The control is not entering in to the
(void)applicationWillTerminate:(UIApplication *)application  
when I pressed the Home button.
And when I touched the game icon on the screen the game is running from first screen and in log (terminal )it is not showing any values.
And what should I store to resume my game from stored state.
Can you explain where I was wrong ?
Thank You.
© Stack Overflow or respective owner