Adding a pause menu 2 in cocos2d

I found a bug in the pause menu. If you let the iphone or ipod touch rest so that you have to unlock it the game will resume but the pause screen will still be up. This will show you how to fix that.

In the PauseButtonTapped function after

if(_pauseScreenUp ==FALSE)
        {

add the following

CoopShootAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate setPause:TRUE];

Now we need to change the app delegate. In your app delegate .h file add the following.

bool _pauseScreenUp;
//and
@property (nonatomic, assign) bool pauseScreenUp;
-(void)setPause:(bool)UP;

Then at the top of the app delegate.m add where all the other synthesizes are.

@synthesize pauseScreenUp = _pauseScreenUp;

now add in the set pause function

-(void)setPause:(bool)UP
{
        self.pauseScreenUp=UP;
}

Now we need to change this

- (void)applicationDidBecomeActive:(UIApplication *)application {
        [[CCDirector sharedDirector] resume];
}

to this

- (void)applicationDidBecomeActive:(UIApplication *)application {
        if(self.pauseScreenUp==false){
        [[CCDirector sharedDirector] resume];
        }
}

Then add the following to ResumeButtonTapped and QuitButtonTapped.

CoopShootAppDelegate *delegate = [[UIApplication sharedApplication]
delegate];
[delegate setPause:FALSE];
 

Thanks John Chui for pointing this out.
Copy right Britney Lee Johnson September 2010.

This entry was posted in cocos2d. Bookmark the permalink.

5 Responses to Adding a pause menu 2 in cocos2d

  1. Kevin says:

    CoopShootAppDelegate <- error undeclared ?

    Thank you for your tutorials! I just started to read your material. I'm currently working on pause menu stuff and I saw your article here. I know this might be silly but what should "CoopShootAppDelegate" be instead?

    Thanks!

  2. Kevin says:

    oops! I figured it out! I replaced it with the current appDelegate name.

  3. John Chui says:

    Thanks! a useful code! I found two minor amendment.
    On both of the below function,
    -(void)ResumeButtonTapped:(id)sender{}
    -(void)QuitButtonTapped:(id)sender{}

    need to set back the pauseScreenUp property to false.
    CoopShootAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    [delegate setPause:FALSE];

  4. Good info. Lucky me I found your blog by chance (stumbleupon).
    I have book marked it for later!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>