I'm trying to make it so that when I minimize my app the pause screen is displayed and when I return to it, it is still maintained; you would have to tap the resume button to continue playing. I have managed to make it so that the game is paused when the app is minimized but the 'paused state' is not displayed. Also, when i press the pause button, minimize the app and then come back to it, it displays the 'Paused' text and has the resume button, but it resumes the game anyways. How would I fix this issue? It's been bothering me for a while. My Code:
AppDelegate.m
- (SKView*)getSKViewSubview{
for (UIView* s in self.window.rootViewController.view.subviews) {
if ([s isKindOfClass:[SKView class]]) {
return (SKView*)s;
}
}
return nil;
}
- (void)applicationWillResignActive:(UIApplication *)application {
SKView *view = [self getSKViewSubview];
if (view){
view.paused = YES;
}
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
SKView* view = [self getSKViewSubview];
if (view) {
view.paused = YES;
}
}
GamePlayScene.m
-(void)update:(NSTimeInterval)currentTime{
...
if (self.view.paused == YES){
for (SKSpriteNode *node in [self children]){
if ([node.name isEqualToString:@"PauseButton"]){
[node removeFromParent];
[self resumeButton];
}
}
}
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
...
if ([node.name isEqualToString:@"PauseButton"]){
[self runAction:self.buttonSFX];
[self performSelector:@selector(pauseGame) withObject:nil afterDelay:1/60.0];
[node removeFromParent];
[self resumeButton];
self.pausedLabel.hidden = NO;
}
if ([node.name isEqualToString:@"ResumeButton"]){
[self runAction:self.buttonSFX];
self.paused = NO;
[node removeFromParent];
[self pauseButton];
self.pausedLabel.hidden = YES;
[[GameState sharedInstance] saveState];
}
...
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire