0

I'm trying to pause my game when the app gets interrupted! (like Phonecalls, SMS, etc.)

I created a pause menu in my Game Viewcontroller (rush_gamemode).

When I press the pause Button in the game everything works just fine. If I call the method via "applicationWillResignActive" in AppDelegate it does work kind of.

Here's my Code:

in rush_gamemode.h

-(void)goIntoPause;

in rush_gamemode.m

-(void)goIntoPause
{
NSLog(@"RUSH goIntoPause was called!");
self.Button_Pause.hidden = YES;


//--------pause timer-------//

if (self.timerStart) {
    timerWasStarted = YES;
    self.oldTimeNumber = self.timeNumber;
    [self.timerStart invalidate];
    self.timerStart = nil;
}

//--------set up pause menu--------//
self.transparent_subview_background.alpha = 0;

self.Pause_Subview.hidden = NO;
self.Pause_Subview.backgroundColor = [UIColor clearColor];

[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:.75];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[self.transparent_subview_background setAlpha:0.75];
[UIView commitAnimations];
}

in AppDelegate.h

@class rush_gamemode;

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
rush_gamemode* rush;
}

in AppDelegate.m I imported "rush_gamemode.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
rush = [[rush_gamemode alloc] init];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
[rush goIntoPause];   
}

So when I start the App, and press the HomeButton (e.g) or get a Phone call, the console shows the NSLog ("RUSH goIntoPause was called!") but doesn't do anything else..

What am I doing wrong here?

cheers, Niklas

smnk
  • 471
  • 1
  • 6
  • 25
  • 1
    Chances are that the rush instance you have allocated in didFinishLaunchingWithOptions is not the instance that is actually running your game. – Paulw11 Aug 10 '14 at 10:56
  • 1
    It may be easier to have your rush class subscribe to the will resign active notification http://stackoverflow.com/questions/9011868/whats-the-best-way-to-detect-when-the-app-is-entering-the-background-for-my-vie – Paulw11 Aug 10 '14 at 11:03

0 Answers0