I tried to search everywhere in the code:Explained documentry what it does when going to background, or if it is even paused sometime, but to no avail- can someone direct me
For me did not work none of one provided solutions. I did found another way how to do it.
// In the AppDelegate
- (void)applicationWillResignActive:(UIApplication *)application
{
if ([self.window.rootViewController isKindOfClass:[GameViewController class]]) {
GameViewController *vc = (GameViewController*)self.window.rootViewController;
[vc pauseGame];
[vc.view addObserver:vc
forKeyPath:@"paused"
options:NSKeyValueObservingOptionNew
context:nil];
}
}
// In the GameViewController
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
SKView *skView = (SKView*)self.view;
MainGame *mainGame = (MainGame*)skView.scene;
if ([keyPath isEqualToString:@"paused"] &&
[[change objectForKey:NSKeyValueChangeNewKey] boolValue] == NO &&
[mainGame isGameInProgress]) {
[self.view removeObserver:self forKeyPath:@"paused" context:nil];
skView.paused = YES;
}
}